我的应用程序中有一个WKWebview,它应该显示音频的录制按钮。但是,按钮本身不可见,并且会显示一些错误,但是在Safari浏览器中可以看到相同的按钮,并且该按钮也可以用于音频记录和播放。
func createWebView(){
let preferences = WKPreferences()
preferences.javaScriptEnabled = true
preferences.javaScriptCanOpenWindowsAutomatically = true
preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")
let userContentController = WKUserContentController()
userContentController.add(self, name: "observe")
let configuration = WKWebViewConfiguration()
configuration.preferences = preferences
configuration.allowsAirPlayForMediaPlayback = true
configuration.allowsInlineMediaPlayback = true
configuration.allowsPictureInPictureMediaPlayback = true
configuration.mediaTypesRequiringUserActionForPlayback = .audio
configuration.userContentController = userContentController
webView = WKWebView(frame: view.bounds, configuration: configuration)
webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
webView.uiDelegate = self
webView.navigationDelegate = self
view.addSubview(webView)
}