This is possible, but you have to use a workaround. First of all you indeed need to set your permissions in the info.plist.
<key>NSMicrophoneUsageDescription</key>
<string>If you want to use the microphone, you have to give permission.</string>
<key>NSCameraUsageDescription</key>
<string>If you want to use the camera, you have to give permission.</string>
After this you have to inject Javascript at the start of the document of the WebView. You could to this by adding a .js document to your project. the code in here would look like this:
//injects this into webpage to listen to the camera request
(function() {
if (!window.navigator) window.navigator = {};
//if getuserMedia is called -> If the user requests native camera
window.navigator.getUserMedia = function() {
webkit.messageHandlers.callbackHandler.postMessage(arguments);
}
})();
In your viewController file, injecting this into the WebView would look like this:
override func loadView() {
let userScriptURL = Bundle.main.url(forResource: "UserScript", withExtension: "js")!
let userScriptCode = try! String(contentsOf: userScriptURL)
let userScript = WKUserScript(source: userScriptCode, injectionTime: .atDocumentStart, forMainFrameOnly: false)
let webConfiguration = WKWebViewConfiguration()
webConfiguration.userContentController.addUserScript(userScript)
}
This works for both camera and microphone use like you are trying to do.