Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap deviceready event only fires when app loses focus

I have installed the latest version of phonegap via npm, and have recently updated my iPhone SE to iOS 10. Now, when I run "phonegap run ios" when my device is connected via a USB cable to my iMac, the app loads, I get a debug alert from the app.bindEvents function, but the deviceready event is not fired. That is, however, until my app loses focus (by double tapping the home button), at which point my debug alert in onDeviceReady fires.

I assumed it was something to do with my app, so I removed all third-party plugins and all the superfluous javascript, but still the same happened. So I created a brand new app which installs the default Phonegap "Connecting to device..." page, and even that does it, even though I haven't modified it in any way. Again, when the app loses focus, I get the "Device is Ready" message.

Does anybody have any ideas why this might be happening?

like image 575
b4tch Avatar asked Sep 28 '16 00:09

b4tch


1 Answers

This post has the resolution: Cordova app hanging during startup on iOS 10 (beta)

To quote:

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

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

So just change the above meta tag in your index.html file and the deviceready event fires.

like image 121
b4tch Avatar answered Nov 08 '22 11:11

b4tch