WKWebView不允许在应用程序中访问摄像机

WKWebView不允许在应用程序中访问摄像机

本文介绍了WKWebView不允许在应用程序中访问摄像机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试与多个用户进行电话会议,因此通过使用Kurento服务器,我们已经实现了这一目标,并且可以在Safari浏览器中正常工作.但是当涉及到WebView/WKWebView中的实现时.它甚至不要求权限.

We are trying to make a conference call with multiple users, So by using Kurento server we have achieved this and it's working on safari browser. But when it comes to implementation in WebView / WKWebView. It does not even ask for permissions.

@IBOutlet weak var webViewContainer: UIView!
var webView: WKWebView!

override open func loadView() {
    super.loadView()

    let webConfiguration = WKWebViewConfiguration()
    webConfiguration.ignoresViewportScaleLimits = true
    webConfiguration.suppressesIncrementalRendering = true
    webConfiguration.allowsInlineMediaPlayback = true
    webConfiguration.allowsAirPlayForMediaPlayback = false
    webConfiguration.allowsPictureInPictureMediaPlayback = true
    webConfiguration.mediaTypesRequiringUserActionForPlayback = .all
    webConfiguration.requiresUserActionForMediaPlayback = true
    webView = WKWebView(frame: webViewContainer.frame, configuration: webConfiguration)
    webView.uiDelegate = self
    webView.navigationDelegate = self
    webView.sizeToFit()
    webView.backgroundColor = .black
    webView.isOpaque = false
    self.webViewContainer.addSubview(webView)

}

func webContentController()-> WKUserContentController {
    let contentController = WKUserContentController()
    let script = try! String(contentsOf: Bundle.main.url(forResource: "WebRTC", withExtension: "js")!, encoding: String.Encoding.utf8)
    contentController.addUserScript(WKUserScript(source: script, injectionTime: WKUserScriptInjectionTime.atDocumentStart, forMainFrameOnly: true))
    contentController.add(self, name: "callbackHandler")
    return contentController
}

override func viewDidLoad() {
    super.viewDidLoad()
    guard let url = URL (string: urlStr) else { return
    }
    let myRequest = URLRequest(url: url)
    self.webView.load(myRequest)
}

我什至在safariViewController中都尝试过此链接,但它并不要求相机许可.

I even have tried this link in safariViewController, but it does not ask for camera permissions.

推荐答案

您是否遵循了文档中的步骤?最重要的部分是NSCameraUsageDescription/NSMicrophoneUsageDescription必须出现在 info.plist 文件

Did you follow the steps from the documentation?The most important part is the NSCameraUsageDescription / NSMicrophoneUsageDescription must be present inside the info.plist file

这篇关于WKWebView不允许在应用程序中访问摄像机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 12:59