Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link to Settings->Privacy->Location Services in iOS phonegap app

Tags:

cordova

I'm using phonegap to make an app, and when a user doesn't allow a certain permission (GPS for example), then the app doesn't ask again the next time they use that feature and I thought the best I could do is just display a message like this:

Please go to iOS Settings > Privacy > Location Services to enable the app to access your location

But I just noticed that the maps app give this message:

Turn On Location Services to Allow Maps to Determine Your Location

And it has the option of Settings or Cancel. If you click Settings, it takes you right to the location services part of settings so that you can enable it.

My question is, how can I link to that part of settings with a phonegap app?

like image 607
aharris88 Avatar asked Sep 30 '13 22:09

aharris88


1 Answers

In iOS >= 8 you can open the application setting panel using:

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];

It's very easy to write a cordova plugin that open that panel from the js layer. To make a portable and stable plugin you should check for the existence of that variable before using it (in iOS < 8).

See the iOS UIApplication documentation for more information.

Ore use an existing cordova settings plugin.

like image 169
lifeisfoo Avatar answered Oct 11 '22 18:10

lifeisfoo