Can we use allowFileAccessFromFileURLs=true to access file:// urls from an app?

In our game app, we have screens before/after game levels which are transparent wk webviews. This works great. We have interesting, complex css-based animations. We recently added some Lottie animations, which use a javascript fetch() on a .json file, and that throws a CORS error since you can't normally fetch file:// urls from the app bundle. 

The error is eliminated if we set allowFileAccessFromFileURLs to true, but it's an undocumented preference of webkit (not a secret iOS method). It's clearly included in the public WebKit github (in WKPreferences.mm).

We have other ideas for workaround, such as JS injection. 

Is allowFileAccessFromFileURLs OK to set to TRUE? 

Is it a risk of app rejection, and/or a significant risk of being removed int he future, and/or and otherwise bad idea? Do you have any other tips about loading data into web views in-app? 

Replies

For those reading along at home, michaeld is geting help on their main issue via another channel. Here on DevForums I want to focus on this:

but it's an undocumented preference of webkit (not a secret iOS method). It's clearly included in the public WebKit github (in WKPreferences.mm).

Your rationale is doubly flawed here:

  • Just because something is visible in open source does not make it a supported API.

  • Just because something is a preference rather than a exported callable symbol does not make it supported API.

Is it a risk of app rejection, and/or a significant risk of being removed in the future, and/or and otherwise bad idea?

I think “bad idea” covers it (-: Preferences are not considered API, except in the very rare occasions where we document them as such [1].

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] I’m actually struggling to think of any right now but I’m sure there are some examples.

So what's the workaround for this? @michaeld @eskimo

Did you change the setting 'allowFileAccessFromFileURls' in the options after all??

@t04 @michaeld