[英]WKWebView does not allow camera access in application
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.我们正在尝试与多个用户进行电话会议,因此通过使用 Kurento 服务器我们已经实现了这一点并且它正在 safari 浏览器上工作。 But when it comes to implementation in
WebView
/ WKWebView
.但是说到
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.我什至在
safariViewController
中尝试过此链接,但它不要求相机权限。
这是 WKWebView 目前已知的限制,详情请参阅chrome 问题
It's a Bug, the WkWebView has limited support to the WebRTC It's now working since IOS 14.3 version这是一个错误,WkWebView 对 WebRTC 的支持有限 它从 IOS 14.3 版本开始工作
But to get this working, you need to set properties requiresUserActionForMediaPlayback = false allowsInlineMediaPlayback = true但是要使其正常工作,您需要设置属性 requiresUserActionForMediaPlayback = false allowedInlineMediaPlayback = true
In my case, I need camera open for account identifier.就我而言,我需要打开相机以获取帐户标识符。 Setting config for webview below work for me:
为下面的 webview 设置配置对我有用:
webConfiguration.allowsInlineMediaPlayback = true webConfiguration.mediaTypesRequiringUserActionForPlayback = [] webConfiguration.allowsInlineMediaPlayback = true webConfiguration.mediaTypesRequiringUserActionForPlayback = []
I had to do this:我必须这样做:
import AVFoundation
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AVCaptureDevice.requestAccess(for: .audio) { haveMicAccess in
print("Access to Microphone: \(haveMicAccess)")
}
return true
}
...
}
It still asks me each time I use the camera with getUserMedia() in the page script too.每次我在页面脚本中使用带有 getUserMedia() 的相机时,它仍然会问我。 But without the above code getUserMedia is null. The above code triggers the request for access to the microphone so long as you provide a message in the info.plist for
NSMicrophoneUsageDescription
但是如果没有上面的代码,getUserMedia 是 null。只要您在 info.plist 中为
NSMicrophoneUsageDescription
提供一条消息,上面的代码就会触发访问麦克风的请求
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.