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
DaveAlden
  • 30,083
  • 11
  • 93
  • 155

2 Answers2

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.

jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • Where to add the meta tag. In my index.html or some other file. I am also facing the same issue. Please help. – Warrior Sep 14 '16 at 16:58
  • 1
    Add to the section of index.html. See [cordova-plugin-whitelist docs](https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/#content-security-policy/), but note this plugin doesn't need to be installed for iOS to pick up the meta tag. – DaveAlden Sep 14 '16 at 17:02
  • I am still getting the error : [PDFAnnotation initWithWebView:]: unrecognized selector sent to instance 0x79684f20 – Warrior Sep 14 '16 at 17:07
  • I am calling the PDFAnnotation from javascript . This is working fine in iOS 9.3 , from yesterday after the update it is crashing – Warrior Sep 14 '16 at 17:08
  • 1
    @Warrior that error has nothing to do with this Content-Security-Policy issue. It's most likely a plugin is not working with iOS 10. – DaveAlden Sep 14 '16 at 17:39
  • OMG , Thanks for the info. Let me try update the cordova version – Warrior Sep 14 '16 at 17:52
  • 2
    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! – Ionian316 Sep 26 '16 at 15:13
  • 2
    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. – Chris Rae Oct 04 '16 at 03:23
  • You just saved half of my hair from being pulled out. – Tom Kincaid Oct 06 '16 at 16:07
  • @Tom Kincaid ha ha, glad I could help save your hair! Too late for me though - bald as a coot :-) – DaveAlden Oct 06 '16 at 16:24
  • First result on google, worked for me. Strangely we have this ancient App in the stores which actually still works. – Mathijs Segers Oct 17 '16 at 06:22
  • 5
    Oddly, I'm having exact same issue. Unluckily, adding the entries in the meta tag didn't work for me. – Ladmerc Mar 01 '17 at 22:43
  • @Ladmerc - 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. – nOOb iOS Oct 31 '17 at 15:34
  • @DaveAlden - 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? – nOOb iOS Nov 06 '17 at 15:16
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

user2981810
  • 379
  • 4
  • 11