I new to developing with swift and currently trying to develop a iOS app with Swift UI. Part of my app uses a separately developed Augmented Reality web app that I was planning on accessing through a WKWebView . Currently I can access the web app this fine through Safari and SFSafariViewController and get video/camera input just fine. However, with the WKWebview it just shows as a blank screen with the alert WebRTC issue-! navigator.mediaDevices not present in your browser.
Is this a limitation on WKWebView and is there anyway around this? I have NSCameraUsageDescription already configured in my info.plist. I have tried:
My code is as follows:
import Foundation
import SwiftUI
import WebKit
struct SwiftUIWebView: UIViewRepresentable {
@ObservedObject var viewModel: WebViewModel
let webView = WKWebView()
func makeUIView(context: UIViewRepresentableContext<SwiftUIWebView>) -> WKWebView {
self.webView.configuration.allowsInlineMediaPlayback = true
self.webView.configuration.allowsAirPlayForMediaPlayback = false
self.webView.configuration.allowsPictureInPictureMediaPlayback = true
self.webView.configuration.mediaTypesRequiringUserActionForPlayback = .all
self.webView.configuration.preferences.javaScriptEnabled = true
self.webView.navigationDelegate = context.coordinator
self.webView.load(URLRequest(url: url))
return self.webView
}
func updateUIView(_ uiView: WKWebView, context: UIViewRepresentableContext<SwiftUIWebView>) {
return
}
class Coordinator: NSObject, WKNavigationDelegate {
private var viewModel: WebViewModel
init(_ viewModel: WebViewModel) {
self.viewModel = viewModel
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print("Web Page Loaded")
}
}
}