I have a problem playing a youtube video (embed url) within a WKWebView inside a SwiftUI view.
This is my SwiftUI WebView code
import SwiftUI
import UIKit
import WebKit
struct WebView: UIViewRepresentable {
let url: String
func makeUIView(context: Context) -> WKWebView {
let webViewConfig = WKWebViewConfiguration()
webViewConfig.mediaTypesRequiringUserActionForPlayback = .all
webViewConfig.allowsInlineMediaPlayback = true
return WKWebView(frame: .zero, configuration: webViewConfig)
}
func updateUIView(_ view: WKWebView, context: UIViewRepresentableContext<WebView>) {
view.load(request)
}
}
I use this WebView like this Webview(url: "YOUTUBEEMBEDVIDEOURLHERE"), the point is the following, first time I get into the screen and click on play button that the url renders everything goes very nice, at this point, I go back (using NavigationView) and get into the same screen again and click on play the video again and then I get the crash.
Crash info
Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Required target entitlement is missing}>
[ProcessSuspension] 0x1479e9930 - ProcessAssertion: Failed to acquire RBS Background assertion 'WebProcess Background Assertion' for process with PID 60999, error: Error Domain=RBSAssertionErrorDomain Code=3 "Required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Required target entitlement is missing}
Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>
ProcessAssertion: Failed to acquire RBS Background assertion 'WebProcess Background Assertion' for process with PID 60999, error: Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}
_userSettingsForUser : (null)
_WebFilterIsActive returning: NO
I tried enabling background permissions and it didn't work
Could be related with this bug https://developer.apple.com/forums/thread/121822 ?