user2673664 user2673664 - 9 days ago 5
Swift Question

Error When using "WKAudiovisualMediaTypeNone" in Swift 3

Trying to add

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

Error


"Use of unresolved identifier 'WKaudiovisualMediaTypeNone'"


in this context

required init?(coder aDecoder: NSCoder) {
let webConfiguration = WKWebViewConfiguration()
webConfiguration.allowsInlineMediaPlayback = true
webConfiguration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone; // Error getting here
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)