Deviceready not firing when using ionic native http?

#1

I’m running into a really weird issue. I’m trying to run my app on iOS with the @ionic-native/http plugin but as soon as I use that plugin to make http requests, the device ready event seems to stop working.

At first I was using @angular/http for http requests which worked fine for android but on iOS I couldn’t get it to work, I always got the
Response with status: 0 for URL: null
error even though I have
<access origin="*" />
in my config.xml and
<meta http-equiv="Content-Security-Policy" content="default-src gap://ready file://* *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
in my index.html

So I switched to @ionic-native/http because I read that it would work better on iOS.
But now I’m having the issue stated above, and I have no clue whats going on.
Here’s my code from app.component.ts (simplified) which should run when the app starts:

constructor(public platform: Platform, ...) {
    this.initializeApp();
}

initializeApp() {
    this.platform.ready().then(() => {
      console.log("ready!");
      ...
    });
}

And sure enough, when using @angular/http to do api calls (@ionic-native/http is being imported but not used) I get this output in xcode (first the “ready!” gets printed, then comes the http error):

2018-07-28 11:17:04.022127+0200 testapp[1997:23420] Apache Cordova native platform version 4.5.5 is starting.
2018-07-28 11:17:04.022466+0200 testapp[1997:23420] Multi-tasking -> Device: YES, App: YES
2018-07-28 11:17:04.034841+0200 testapp[1997:23420] CDVWKWebViewEngine: trying to inject XHR polyfill
2018-07-28 11:17:04.123970+0200 testapp[1997:23420] [MC] Lazy loading NSBundle MobileCoreServices.framework
2018-07-28 11:17:04.124943+0200 testapp[1997:23420] [MC] Loaded MobileCoreServices.framework
2018-07-28 11:17:04.132454+0200 testapp[1997:23420] CDVWKWebViewEngine will reload WKWebView if required on resume
2018-07-28 11:17:04.132712+0200 testapp[1997:23420] Using Ionic WKWebView
2018-07-28 11:17:04.133548+0200 testapp[1997:23420] [CDVTimer][console] 0.105023ms
2018-07-28 11:17:04.133847+0200 testapp[1997:23420] [CDVTimer][handleopenurl] 0.112057ms
2018-07-28 11:17:04.135903+0200 testapp[1997:23420] [CDVTimer][intentandnavigationfilter] 1.873970ms
2018-07-28 11:17:04.136148+0200 testapp[1997:23420] [CDVTimer][gesturehandler] 0.079989ms
2018-07-28 11:17:04.138934+0200 testapp[1997:23420] [CDVTimer][file] 2.649069ms
2018-07-28 11:17:04.175063+0200 testapp[1997:23420] [CDVTimer][splashscreen] 35.942078ms
2018-07-28 11:17:04.176348+0200 testapp[1997:23420] [CDVTimer][keyboard] 1.059055ms
2018-07-28 11:17:04.176557+0200 testapp[1997:23420] [CDVTimer][TotalPluginStartup] 43.143988ms
2018-07-28 11:17:06.387081+0200 testapp[1997:23420] Ionic Native: deviceready event fired after 1184 ms
2018-07-28 11:17:06.387557+0200 testapp[1997:23420] ready!
2018-07-28 11:17:06.614921+0200 testapp[1997:23420] ERROR: Response with status: 0 for URL: null
2018-07-28 11:17:06.615529+0200 testapp[1997:23420] ERROR: Response with status: 0 for URL: null

but now if I switch to using @ionic-native/http for http requests, this is the only output I get:

2018-07-28 11:20:25.337628+0200 testapp[2188:26564] Apache Cordova native platform version 4.5.5 is starting.
2018-07-28 11:20:25.337971+0200 testapp[2188:26564] Multi-tasking -> Device: YES, App: YES
2018-07-28 11:20:25.351299+0200 testapp[2188:26564] CDVWKWebViewEngine: trying to inject XHR polyfill
2018-07-28 11:20:25.433276+0200 testapp[2188:26564] [MC] Lazy loading NSBundle MobileCoreServices.framework
2018-07-28 11:20:25.434109+0200 testapp[2188:26564] [MC] Loaded MobileCoreServices.framework
2018-07-28 11:20:25.441683+0200 testapp[2188:26564] CDVWKWebViewEngine will reload WKWebView if required on resume
2018-07-28 11:20:25.441924+0200 testapp[2188:26564] Using Ionic WKWebView
2018-07-28 11:20:25.442643+0200 testapp[2188:26564] [CDVTimer][console] 0.128984ms
2018-07-28 11:20:25.442904+0200 testapp[2188:26564] [CDVTimer][handleopenurl] 0.080943ms
2018-07-28 11:20:25.445300+0200 testapp[2188:26564] [CDVTimer][intentandnavigationfilter] 2.240896ms
2018-07-28 11:20:25.445623+0200 testapp[2188:26564] [CDVTimer][gesturehandler] 0.129938ms
2018-07-28 11:20:25.448412+0200 testapp[2188:26564] [CDVTimer][file] 2.606034ms
2018-07-28 11:20:25.483576+0200 testapp[2188:26564] [CDVTimer][splashscreen] 34.994960ms
2018-07-28 11:20:25.484480+0200 testapp[2188:26564] [CDVTimer][keyboard] 0.753999ms
2018-07-28 11:20:25.484782+0200 testapp[2188:26564] [CDVTimer][TotalPluginStartup] 42.307019ms
2018-07-28 11:20:27.563898+0200 testapp[2188:26564] Ionic Native: deviceready event fired after 1147 ms

It says the device ready event has been fired but the “ready!” doesn’t appear to be printed, which leads me to believe that the event wasn’t actually fired.

What is going on here? Why does changing the way I do my requests break a platform lifecycle event?

I tried removing and re-adding the plugin as well as the entire ios platform, both didn’t help.

Here’s my plugin list:

cordova-plugin-advanced-http 1.11.1 “Advanced HTTP plugin”
cordova-plugin-device 1.1.7 “Device”
cordova-plugin-file 6.0.1 “File”
cordova-plugin-ionic-webview 1.2.1 “cordova-plugin-ionic-webview”
cordova-plugin-splashscreen 4.1.0 “Splashscreen”
cordova-plugin-whitelist 1.3.3 “Whitelist”
ionic-plugin-keyboard 2.2.1 “Keyboard”
phonegap-plugin-barcodescanner 6.0.8 “BarcodeScanner”

And here’s my ionic info:

Ionic:

ionic (Ionic CLI) : 4.0.1 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.1.0

Cordova:

cordova (Cordova CLI) : 8.0.0
Cordova Platforms : ios 4.5.5

System:

ios-deploy : 1.9.2
NodeJS : v9.3.0 (/usr/local/Cellar/node/9.3.0_1/bin/node)
npm : 5.6.0
OS : macOS Sierra
Xcode : Xcode 9.2 Build version 9C40b

Environment:

ANDROID_HOME : not set

I’m running macOS in a virtual machine on windows because I don’t have access to a real mac. I don’t think that’s the issue, but I thought I’d mention it anyway. I’m using xcode’s simulator here, but I tested the app on a friend’s real iPhone and it doesn’t work there as well.

Does anyone know how to get @angular/http to work on iOS without the CORS Response with status: 0 for URL: null problem or how to solve the issue with @ionic-native/http here? Either way is fine for me, I just want to be able to make http requests in my app…

#2

problem solved, @ionic-native/http plugin was in “imports” not “providers” of app.moudle.ts
It worked that way for @angular/http. I don’t know why it’s different for @ionic-native/http…