2

I'm using this code to redirect to iOS settings for the location:

NSURL *url = [NSURL URLWithString:@"App-Prefs:root=LOCATION_SERVICES"];

if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}

But it is just redirecting to settings and not in location or bluetooth settings. Does anybody know if is any way to redirect to iOS location settings?

Thank you

Jaydeep Vora
  • 6,085
  • 1
  • 22
  • 40
EgzonArifi
  • 830
  • 1
  • 11
  • 23
  • user is now able to override our requestAlwaysAuthorization and downgrade it to requestWhenInUseAuthorization - Which means as a developer we now have to supply both descriptions in the Info.plist add a new key NSLocationAlwaysAndWhenInUseUsageDescription – Jevgenij Kononov Mar 26 '18 at 08:19
  • I have it already in my Info.plist file, but I think the problem is in this 'App-Prefs:root=LOCATION_SERVICES' – EgzonArifi Mar 26 '18 at 08:22
  • Have you checked this page: https://stackoverflow.com/questions/44424092/location-services-not-working-in-ios-11? it was useful for me previously when I have faced with the same problem – Jevgenij Kononov Mar 26 '18 at 08:24

3 Answers3

2

Declare url as:

NSURL *url = [NSURL URLWithString:@"App-Prefs:root=LOCATION_SERVICES"];

thus:

if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL: url];
}

NOTE:

The above approach should work for iOS 10.x and below (you could check: How to programmatically open the WIFI settings in Objective-C on iOS 10). However, the "app-prefs" URL scheme is not supported by Apple! prefs URLs are considered as private APIs, the only documented preference URL is the UIApplicationOpenSettingsURLString. Obviously, is has nothing to do with the used programming language; Related:

Roughly speaking, you are not able to do such a navigation anymore on iOS 11.

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
  • It looks same as with completionHandler, I think that 'App-Prefs:root=LOCATION_SERVICES' has been deprecated in iOS 10 and up, but I'm thinking if there is any other way. – EgzonArifi Mar 26 '18 at 08:19
  • @EgzonArifi So, based on my answer, trying to open the url leads you to the settings, is it correct? – Ahmad F Mar 26 '18 at 08:22
  • Yes, but with that it was planned to redirect to Settings>Privacy>Location Services. Thanks – EgzonArifi Mar 26 '18 at 08:24
0

You can use UIApplicationOpenSettingsURLString. If your application uses location data or bluetooth you will see location and bluetooth settings there.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
Andrew Romanov
  • 4,774
  • 3
  • 25
  • 40
0

First: Click on project name >> target>> Info >> url Types >> URL Schemes. For example you can see the screenshot. enter image description here

Then use the code:

-(IBAction)openSettingViewToEnableLocationService:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
}
Mukesh
  • 777
  • 7
  • 20