简体   繁体   English

无法访问 WKWebView 中的麦克风和摄像头

[英]Unable to access Microphone and Camera in WKWebView

WKWebView is not asking permission for camera and microphone in the app. WKWebView不会在应用程序中请求对摄像头和麦克风的许可。 When I load the same url in safari browser it asks the permission for camera and microphone, and video call works perfectly.当我在 safari 浏览器中加载相同的 url 时,它会询问摄像头和麦克风的权限,视频通话效果很好。 But when I embed this in WKWebView permission is not asked even I have given both camera and microphone permission in plist file.但是,当我将其嵌入WKWebView即使我在 plist 文件中授予了相机和麦克风权限,也不会询问权限。 The same thing is not working even in UIWebView and safari view controller.即使在UIWebView和 safari 视图控制器中,同样的事情也不起作用。 I have referred below links but still its not working.我已经提到了以下链接,但仍然无法正常工作。 Enable Camera and Mic access in wkwebview , How do I prevent a WKWebView from presenting the Camera modal if a user has denied access to the camera? 在 wkwebview 中启用摄像头和麦克风访问, 如果用户拒绝访问摄像头如何防止 WKWebView 显示摄像头模式? Can anybody provide any solution?任何人都可以提供任何解决方案吗?

Why not do the asking permission for camera and microphone in the app yourself ?为什么不自己在应用程序中请求相机和麦克风的许可?

You have the full control over your app.您可以完全控制您的应用程序。

    //Camera
    AVCaptureDevice.requestAccess(for: AVMediaType.video) { response in
        if response {
            //access granted
        } else {

        }
    }

    //Photos
    let photos = PHPhotoLibrary.authorizationStatus()
    if photos == .notDetermined {
        PHPhotoLibrary.requestAuthorization({status in
            if status == .authorized{
                ...
            } else {}
        })
    }

If all granted, then do the js video call.如果全部通过,则进行js视频通话。

If not, show tips for the use to grant it.如果没有,请显示使用提示以授予它。

  • And, it's easy to do that js call native , native call js而且,很容易做到js调用nativenative调用js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM