音频记录按钮在WKWebView中不可见,但在Safari浏览器中可见

时间:2019-05-27 08:18:24

标签: ios swift iphone wkwebview audio-recording

我的应用程序中有一个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)
}

0 个答案:

没有答案