2

I’m converting an app that is largely based on webviews to WKWebView. At first, I was prevented from accessing the accelerometer because of CORS cross domain policy issues. When I solved that, the video that would play without a problem, now no longer plays.

How do I get enable both video playback and access to the accelerometer?

Basically if I add this line in the snippet blow:

configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")

then the accelerometer works, video doesn't. Remove this line, the video plays but instead of the accelerometer enabled screen, an error is displayed.

let webView: WKWebView = {
     let configuration = WKWebViewConfiguration()
     configuration.mediaTypesRequiringUserActionForPlayback = []
     configuration.allowsInlineMediaPlayback = true
     configuration.preferences.setValue(true, forKey: "allowFileAccessFromFileURLs")

     return WKWebView(frame: .zero, configuration: configuration)
 }()

They were working together with the UIWebview, but with my changes to WKWebView I can't get them to work both together.

mfaani
  • 33,269
  • 19
  • 164
  • 293
Edan
  • 167
  • 14
  • "an error is displayed." what error? – mfaani Jun 05 '19 at 19:39
  • @Honey The following error: `ERROR: Local usage with file:// urls is limited due browser security restrictions! Use a localhost server (like the krpano Testing Server) for local testing! Just start the krpano Testing Server and refresh this page.` – Edan Jun 05 '19 at 20:15

0 Answers0