Adam Norbäcker Adam Norbäcker - 25 days ago 8
Javascript Question

Phonegap iOS app is asking for permissions only when minimized

I'm new to making apps with Phonegap. Everything worked great with the Android version, asking for permissions and such. But when it comes to iOS, the app is not asking for permissions nor are alerts showing up, unless I minimize the app and open it again.

The first time I minimize, it shows an alert box. The second time I minimize, it shows up the permission box.

Then, for every time I need geolocation, I have to minimize and open the app again.

Why is the app reacting only when it open up? This is only happening to iOS, not Android.

I have tried those things:

Cordova geolocation in IOS not working

Location permission alert on iPhone with Cordova

I'm sorry if my English is bad, it isn't my main language. Same thing with writing and questions as I have dyslexia. But I try my best.

My code for alertbox:

document.addEventListener("deviceready", function() {
alert('iPhone geo started');
});

Answer

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'">