在这里使用我的快速应用程序。
下面是我的代码,
struct WebView: UIViewRepresentable {
@State var allowsInLineMediaPlayback = true
let request: URLRequest//pass the website to webkit
func makeUIView(context: Context) -> WKWebView {
let configuration = WKWebViewConfiguration()
configuration.allowsInlineMediaPlayback = true
configuration.mediaTypesRequiringUserActionForPlayback = []
let webView = WKWebView(frame: .zero, configuration: configuration)
return webView
}
func updateUIView(_ uiView: WKWebView, context: Context) {
uiView.load(request)
}
}
class ViewController: UIViewController {
var webView = WKWebView()
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(didBecomeActive),
name: UIApplication.didBecomeActiveNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(willResignActive),
name: UIApplication.willResignActiveNotification, object: nil)
}
@objc func willResignActive(){
disableIgnoreSilentSwitch(webView)
}
@objc func didBecomeActive() {
//Always creates new js Audio object to ensure the audio session behaves correctly
forceIgnoreSilentHardwareSwitch(webView, initialSetup: false)
}
并且我在使用webView时出现此部分错误
disableIgnoreSilentSwitch(webView)
错误状态 无法将类型'((WKWebView,WKNavigation?)->()'的值转换为预期的参数类型'WKWebView' 提前致谢。 如果有帮助,我正在使用此处的代码作为参考。 How to force WKWebView to ignore hardware silent switch on iOS?