简体   繁体   中英

Open location settings not working in iOS 11

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

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.

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]];

First: Click on project name >> target>> Info >> url Types >> URL Schemes. For example you can see the screenshot. 在此处输入图片说明

Then use the code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM