Cordova 6 application cannot load from file: // path

I upgraded an existing application to Cordova 6.0.0, and I have problems running it on an iOS device with Xcode 7.2.1 oriented to iOS 9.

I installed the WKWebView plugin: cordova-plugin-wkwebview-engine 1.0.2

When starting an application that is built using AngularJS, one of the first things he tries to do is open the json file:

 $http.get('data/config.json').success(function(data) { // do stuff }); 

But we get this error in the web view console:

 XMLHttpRequest cannot load file:///var/mobile/Containers/Bundle/Application/ E9D74C94-ADC6-410F-9F41-7CE63CB7877F/Milk.app/www/data/config.json. Cross origin requests are only supported for HTTP. 

In the config.xml file we have:

 <access origin="*" subdomains="true" /> 

Why is the file: // request blocked, and how can I fix it?

* edit *

According to the plugin :

"In iOS 9, Apple fixed an issue that existed through iOS 8, where you cannot upload locale files using the file: //, and resort to using the local web server. However, you still cannot use XHR from the file: // protocol without CORS enabled on your server. "

What do they mean by "your server"? Which server? We upload a local file, no server!

+5
source share
2 answers

EDIT:

The ion team is working on a plugin for the WKWebViewEngine plugin and fixed some XHR problems, but I'm not sure if this is fixed. You can take a look at https://github.com/driftyco/cordova-plugin-wkwebview-engine

Old answer: This is a known issue, local file:// url XmlHttpRequests not resolved in WKWebViewEngine ( https://issues.apache.org/jira/browse/CB-10143 )

For more known issues, see https://issues.apache.org/jira/browse/CB-10237?jql=labels%20%3D%20wkwebview-known-issues

If you want to make a local ajax call to work, you should use the wkwebview-engine-localhost plugin ( https://github.com/apache/cordova-plugins/tree/master/wkwebview-engine-localhost )

Or the Telerik WKWebView WKWebView ( https://github.com/Telerik-Verified-Plugins/WKWebView ).

Both of them will use a local web server, which solves some of the known limitations of WKWebView.

+6
source

I also had problems with local file access, including SQLite access. I created a plugin based on some sample code that I found, modified it to make it work, and now it works great. Ymmv

https://github.com/TheMattRay/cordova-plugin-wkwebviewxhrfix

+1
source

Source: https://habr.com/ru/post/1244313/


All Articles