Sven van de Scheur
Sven van de Scheur

Reputation: 1903

Cordova iOS Cross origin requests are only supported for HTTP

I'm building an iOS app and recently upgraded cordova-ios to 4.1.0 and started using: cordova-plugin-wkwebview-engine.

The problem is that now I get the error message Cross origin requests are only supported for HTTP while trying to load dependencies, so the app won't start.

It's trying to load systemjs dependencies over file://, but I included in my config.js.

I have no clue how to fix this. Does anyone have experience with this bevaviour?

cordova version: 6.1,0 cordova ios version: 4.1.0

related config.xml bit:

<access origin="*" />
<feature name="CDVWKWebViewEngine">
  <param name="ios-package" value="CDVWKWebViewEngine" />
</feature>

<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />

Upvotes: 21

Views: 15370

Answers (6)

michal zagrodzki
michal zagrodzki

Reputation: 236

If you work with cordova-ios ^6.0.0. you need only to modify your config.xml file:

<platform name="ios">
  ...
   <preference name="scheme" value="app" />
   <preference name="hostname" value="localhost" /> 
  ...
</platform>

No need to install any additional plugins.

See Cordova iOS 6.0.0 Released for more info.

Upvotes: 8

Thorsten
Thorsten

Reputation: 91

I had the same issue with my ionic v1 Cordova project. For me the solution was to migrate to capacitor, like this:

  • Start a New Ionic v1 project (% ionic start Bienchen blank --type ionic1)
  • Answer "yes" when the cli asked if to integrate "capacitor".
  • Checkout my Sources to the www-folder of the new Ionic v1 project
  • Build the project with capacitor (% ionic capacitor build iOS)

Keep in mind the the Cordova config.xml than is not longer used, instead configure in Xcode Project.

Upvotes: 0

ahovakimyan
ahovakimyan

Reputation: 149

For Cordova iOS 6+ just need to install the following plugin.

cordova plugin add https://github.com/AraHovakimyan/cordova-plugin-wkwebviewxhrfix

This plugin does not depend on any other additional plugins and does not require additional permissions.

Upvotes: 13

Eric
Eric

Reputation: 10626

Install this one plugin (cordova-ios 6+)

  cordova plugin add https://github.com/globules-io/cordova-plugin-ios-xhr

then set

  <preference name="AllowUntrustedCerts"  value="true" />
  <preference name="InterceptRemoteRequests" value="all" />
  <preference name="allowFileAccessFromFileURLs" value="true" />
  <preference name="allowUniversalAccessFromFileURLs" value="true" />

Upvotes: 15

Avinash Tribhuvan
Avinash Tribhuvan

Reputation: 194

Install the following plugins:

cordova plugin add cordova-plugin-wkwebview-engine    
cordova plugin add cordova-plugin-wkwebview-file-xhr    
cordova plugin add https://github.com/TheMattRay/cordova-plugin-wkwebviewxhrfix

Add to config.xml:

<platform name="ios">
  ...
   <preference name="WKWebViewOnly" value="true"/>
  ...
 </platform> 

Upvotes: 12

JLavoie
JLavoie

Reputation: 17596

I had the same issue with my cordova project (actually Ionic v1) and I fix it with the following command:

cordova plugin add https://github.com/apache/cordova-plugins.git#wkwebview-engine-localhost

This will install a webserver that runs locally and the error should be gone after that. After you run that command, just run:

cordova prepare ios

or remove all plugins and reinstall:

rm -rf plugins/
cordova platform add ios

Make sure you have this in your config.xml:

<access origin="*" />
<feature name="CDVWKWebViewEngine">
  <param name="ios-package" value="CDVWKWebViewEngine" />
</feature>

<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" /> 

Upvotes: 5

Related Questions