So I noticed uiwebview was upgraded to WKWebview which is great, it’s much faster with the nitro JavaScript engine in iOS, although I have a problem I want to run a web page from the documents directory and it doesn’t seem to work, on investigation into the source code I see that when initializing the web view there is no configuration set to allow this, to make this work how can I get this added to the core source.
below is the code needed to be added to Rtt_IPhoneWebViewObject.mm at approx line 133
WKWebViewConfiguration \*theConfiguration = [[WKWebViewConfiguration alloc] init]; [theConfiguration.preferences setValue:@YES forKey:@"allowFileAccessFromFileURLs"]; // needed to run web page from documents directory [theConfiguration.preferences setValue:@YES forKey:@"OfflineApplicationCacheIsEnabled"]; // needed to run web page from documents directory // alternative initialization for web view fWebView = [[WKWebView alloc] initWithFrame:webViewRect configuration:theConfiguration];
I don’t see where this was even mentioned or fixed, uiwebview will load local files but you transitioned to WKWebview on the 22nd nov and you have to handle that differently, this is something I’ve dealt with a lot in native iOS.
If you’re comfortable, you could pull down the source code, make the change, and after you test it, make a pull request to send your changes back up stream.
These are the kinds of things that the community can do to really help!
Unfortunately I’m not a big github user, we use Perforce for our version control, although I could give it a go I’m sure, but if somebody wants to help then I know what the change has to be
This is a breaking change for us - we need local HTML files as we make extensive use of them to display user-facing text from within our app. Currently, we’re using Corona build 3552 as it’s the last version supporting UIWebView. However, there are important fixes ahead of this build (IAP stuff for example).
Looks like it’s a trivial change to allow local HTML files in WKWebView. Can engineering prioritize this?
Fair enough. What’s a solution in the interim? Presumably this is fixable with a plugin that wraps a WXWebView with the configuration in cublah’s original post?
WKWebViewConfiguration \*theConfiguration = [[WKWebViewConfiguration alloc] init]; [theConfiguration.preferences setValue:@YES forKey:@"allowFileAccessFromFileURLs"]; // needed to run web page from documents directory // alternative initialization for web view fWebView = [[WKWebView alloc] initWithFrame:webViewRect configuration:theConfiguration];
Just replace line 134 with those 3 lines and it’s done
In a separate test, I managed to get my web pages loading in a WKWebView, but only from ResourceDirectory, not CachesDirectory. CachesDirectory seems to be off-limits. This was with a much more complicate web page, with require.js, images, handbrake templates and other stuff - don’t know if this affects things, will need to test more.
This fix enables you to load local files from the documents directory, now it’s possible Apple have fixed this the the the last couple of versions of iOS but I know putting this in works on all versions, I’ve been using this in projects for the last 4 years and without it you can not read local files from the documents directory in all versions of iOS. I’m trying to get the fix added.