Reputation: 830
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
Upvotes: 2
Views: 4436
Reputation: 31645
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.
Upvotes: 2
Reputation: 5076
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]];
Upvotes: 0
Reputation: 797
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"]];
}
Upvotes: 0