I am working on a native visionOS app.
I'm running into a problem when websites request fullscreen.
Sample code:
import SwiftUI
import WebKit
struct WebViewWrapper: UIViewRepresentable {
let url: String
func makeUIView(context: Context) -> WKWebView {
let webConfiguration = WKWebViewConfiguration()
webConfiguration.allowsInlineMediaPlayback = false
webConfiguration.mediaPlaybackRequiresUserAction = false
let webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.navigationDelegate = context.coordinator
webView.uiDelegate = context.coordinator
return webView
}
func updateUIView(_ uiView: WKWebView, context: Context) {
if let url = URL(string: url) {
let request = URLRequest(url: url)
uiView.load(request)
}
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
class Coordinator: NSObject, WKNavigationDelegate, WKUIDelegate {
var parent: WebViewWrapper
init(_ parent: WebViewWrapper) {
self.parent = parent
}
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
if navigationAction.targetFrame == nil {
webView.load(navigationAction.request)
}
return nil
}
}
}
struct ContentView: View {
var body: some View {
GeometryReader { geo in
VStack {
WebViewWrapper(url: "https://youtube.com")
.clipShape(RoundedRectangle(cornerSize: CGSize(width: geo.size.width/40, height: geo.size.height/40)))
.padding()
}
}
}
}
#Preview(windowStyle: .automatic) {
ContentView()
}
The error I'm getting: -[AVPlayerViewController enterFullScreenAnimated:completionHandler:] failed with error Invalid call of -[AVPlayerViewController (0x153087600) _transitionToFullScreenAnimated:interactive:completionHandler:]!
Any help would be greatly appreciated.