Reputation: 7
I want to implement GPS access functionality. So main task is if user's GPS is turned off then redirect user to GPS settings page so that user can turn it on.
I tried following code
cordova.plugins.diagnostic.switchToLocationSettings();
But no luck,. I guess it works only for android. Can anyone suggest me some plugin or code which will redirect to GPS setting screen.
Upvotes: 0
Views: 1794
Reputation: 501
I had the same issue in an iOS PhoneGap application. I have installed Cordoava Native Settings plugin. Then called a method for iOS:
cordova.plugins.settings.open(function(){},function(){});
It has successfully opened settings page for location service.
Upvotes: 0
Reputation: 30366
On iOS 8, you can switch to the settings page for your app in the Settings app using some Objective-C:
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: UIApplicationOpenSettingsURLString]];
This page shows permissions specific to your app, so if a user has disabled location access for your app (by clicking "Don't Allow"), they can re-enable it here. Use the cordova.plugins.diagnostic.isLocationAuthorized()
function of cordova-diagnostic-plugin to check if the user has disabled location access for your app.
If they've turned off Location Services entirely, the user will need to use the main menu in the Settings app to navigate to Privacy and re-enable Location Services - AFAIK it's not possible to show this page programmatically. Use the cordova.plugins.diagnostic.isLocationEnabledSetting()
function of cordova-diagnostic-plugin to check if the user has disabled location services.
Update
I've updated the cordova-diagnostic-plugin to support switching to the Settings app. Install the latest version (1.1.1), then call:
cordova.plugins.diagnostic.switchToSettings();
On iOS 7 and below, it's not possible to open the Settings app.
Upvotes: 1