在WKWebView/UIWebView中启用WebRTC支持
我正在webview 中使用 WebRTC 开发颤振应用程序。在 android 上,它按预期工作,但在 iOS 构建上遇到问题。我已阅读线程Apple Support和SO Thread。
两个线程都声明,在 iOS webview 中不允许使用 WebRTC。我在模拟器/真实设备中测试了我的代码,但没有成功。
所以,我的问题是有人知道如何在 iOS webview 中运行 WebRTC?
这就是我显示 webview 的方式
InAppWebView(
initialUrl: widget.callType == AppConstant.INCOMING ? incomingUrl : outGoingUrl,
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
mediaPlaybackRequiresUserGesture: false,
debuggingEnabled: true,
clearCache: true,
javaScriptEnabled: true,
preferredContentMode: UserPreferredContentMode.MOBILE
),
),
onWebViewCreated: (InAppWebViewController controller) {
//web view created
},
androidOnPermissionRequest: (InAppWebViewController controller, String origin, List<String> resources) async {
print('resource list : ${resources.toString()}');
return PermissionRequestResponse(resources: resources, action: PermissionRequestResponseAction.GRANT);
}
);
回答
ios Webview 和 WKWebView 直到现在还没有 WebRTC 支持。
从 ios 14.3 开始,ios 提供对 WKWebView 的支持:https ://leemartin.medium.com/ios-14-3-brings-webrtc-to-wkwebview-closure-gap-on-ios-accessibility-90a83fa6bda2
您需要在手机和/或 Xcode 12.3 中更新 iOS。
此外,根据您的 webview 插件(在我的情况下,我使用的是cordova-plugin-inappbrowser)可能需要修改它以添加视频、相机和VoIP的权限。
- iOS 14.3 has enabled the webrtc access. and it is working. future reader can check the functionality from listed samples https://webrtc.github.io/samples/ by running them in iOS safari browser.