user2673664 user2673664 - 5 days ago 6
Swift Question

Error when using "WKAudiovisualMediaTypeNone"

Trying to add WKAudiovisualMediaTypeNone to mediaTypesRequiringUserActionForPlayback for a WKWebview. But I can't get it to work.

Code error on this row

webConfiguration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;


Error

"Use of unresolved identifier 'WKaudiovisualMediaTypeNone'"


in this context

required init?(coder aDecoder: NSCoder) {
let webConfiguration = WKWebViewConfiguration()
webConfiguration.allowsInlineMediaPlayback = true
webConfiguration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
self.webView = WKWebView(frame: CGRectZero, configuration: webConfiguration)
super.init(coder: aDecoder)
}


Please help

Answer

There is no option with .None. If you don't want to pass anything you can go for below code:

let webConfiguration = WKWebViewConfiguration()
webConfiguration.allowsInlineMediaPlayback = true
if #available(iOS 10.0, *) {
    webConfiguration.mediaTypesRequiringUserActionForPlayback = .all
} else {
    // Fallback on earlier versions
    webConfiguration.mediaPlaybackRequiresUserAction = false
}
self.webView = WKWebView(frame: CGRectZero, configuration: webConfiguration)
Comments