WKWebView does not allow camera access in application

Nasir Khan picture Nasir Khan · Jun 18, 2019 · Viewed 8.6k times · Source

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)
}

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

Answer

vk.edward.li picture vk.edward.li · Jun 18, 2019

This

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