Cordova app hanging during startup on iOS 10
Asked Answered
V

2

31

I just installed Xcode 8 beta in order to test my existing Cordova app in iOS 10 beta (via Simulator). When the app is launched, it just hangs on the loading page - seems the deviceready event is not being fired.

So I also installed iOS 10 beta on my iPad Air (just in case it's a Simulator issue), but I get the same results.

The app works fine on iOS 9.3 (both device and Simulator).

Anyone encountered/fixed this problem?

UPDATE

Other symptoms of this problem include:

  • the app will start correctly if you background the app (switch back to the home screen) then foreground the app (switch back to the app)
  • some plugins will not work correctly until you do the above switching
Valenza answered 16/7, 2016 at 10:24 Comment(0)
V
81

OK, I found the problem and the solution thanks to this post:

It seems that iOS 10 requires additional entries in the Content-Security-Policy meta tag, namely gap: and file:. After adding these, my Content-Security-Policy looks like this:

<meta http-equiv="Content-Security-Policy" content="default-src * gap: file:; style-src 'self' 'unsafe-inline'; img-src 'self' data:; script-src * 'unsafe-inline' 'unsafe-eval'">

And the app starts up and works fine on iOS 10.

Hope this helps others.

Valenza answered 16/7, 2016 at 10:49 Comment(14)
Where to add the meta tag. In my index.html or some other file. I am also facing the same issue. Please help.Arguable
Add to the <head> section of index.html. See cordova-plugin-whitelist docs, but note this plugin doesn't need to be installed for iOS to pick up the meta tag.Valenza
I am still getting the error : [PDFAnnotation initWithWebView:]: unrecognized selector sent to instance 0x79684f20Arguable
I am calling the PDFAnnotation from javascript . This is working fine in iOS 9.3 , from yesterday after the update it is crashingArguable
@Arguable that error has nothing to do with this Content-Security-Policy issue. It's most likely a plugin is not working with iOS 10.Valenza
OMG , Thanks for the info. Let me try update the cordova versionArguable
I was having issues where $http.get() was taking a long time retrieving data on iOS 10 while iOS 9.3 was instantaneous. Adding the two tags fixed this. Thanks!Ephrem
Worked great (and thank you so much as I had pretty much zero debug info here!). In case anyone else is wondering, another symptom of this for me was that the app would start correctly if you switched back to app menu then jumped back into the app. Which makes no sense given the solution but, well, that was what happened.Oliva
You just saved half of my hair from being pulled out.Rebellion
@Tom Kincaid ha ha, glad I could help save your hair! Too late for me though - bald as a coot :-)Valenza
First result on google, worked for me. Strangely we have this ancient App in the stores which actually still works.Tarnopol
Oddly, I'm having exact same issue. Unluckily, adding the entries in the meta tag didn't work for me.Plication
@Plication - Did you able to solve the issue? I am having the same issue in iOS app. Device ready is not fired while loading the html page rather it is fired when we click home button in the simulator.Aerial
@Valenza - I added meta tag, still facing the same issue. Plugin is not called when it loads, but calls when loses focus like pressing home button, bringing notification screen or control centre.. Any ideas?Aerial
E
3

I had the same problem during startup, and even if I did do a double tap on the home button and back to the app, cordova's file system wouldn't write to the device.

I tried a lot of things, but finally fixed it by adding

child-src * gap://ready

to the Content-Security-Policy tag

Epileptic answered 3/8, 2017 at 3:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.