SwiftUI,WKWebView 重复的相机和麦克风权限

huangapple go评论99阅读模式
英文:

SwiftUI, WKWebView repetitive permission camera and microphone

问题

我想要使用 WKWebView 对象打开一个 URL,并且通过授予相机和麦克风权限在该 URL 上进行音频和视频通信。我面临的问题是,每次打开 URL 时,浏览器都会重复要求权限,我希望避免这种情况。是否有一种方法可以只请求一次权限?

我希望使用 WKWebView 打开的浏览器只在第一次请求相机和麦克风权限,而在后续使用时不再提示。当我的应用程序启动时,我需要它直接连接到 web 地址并开始视频通话,而无需再次请求权限。

英文:

WKWebView object, I am opening a URL using the WKWebView object, and I am conducting audio and video communication on that URL by granting camera and microphone permissions. The issue I'm facing is that every time the URL is opened, the browser asks for permissions repeatedly, which I want to avoid. Is there a way to request permissions only once?

I want the browser opened with WKWebView to ask for camera and microphone permissions only once and not prompt for them again in subsequent uses. When my application opens, I need it to connect directly to the web address and start the video call without permissions.

答案1

得分: 0

使用iOS >= 15,您可以使用以下代码进行操作:

@available(iOS 15.0, *)
func webView(
    _ webView: WKWebView,
    requestMediaCapturePermissionFor
    origin: WKSecurityOrigin, initiatedByFrame
    frame: WKFrameInfo,
    type: WKMediaCaptureType,
    decisionHandler: @escaping (WKPermissionDecision) -> Void) {
        decisionHandler(.grant)
    }
英文:

With iOS >= 15 you can do with code:

@available(iOS 15.0, *)
func webView(
    _ webView: WKWebView,
    requestMediaCapturePermissionFor
    origin: WKSecurityOrigin, initiatedByFrame
    frame: WKFrameInfo,
    type: WKMediaCaptureType,
    decisionHandler: @escaping (WKPermissionDecision) -> Void) {
        decisionHandler(.grant)
    }

huangapple
  • 本文由 发表于 2023年6月15日 17:02:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76480860.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定