Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to jump to system setting's location service on iOS10?

Before I asked this question I had try:

  1. Use [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=LOCATION"]];It's work fine on iOS8 and iOS9,but there is nothing happen on iOS10.
  2. Use [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];It's work fine on iOS8 and iOS9,too.However,on iOS10,when the app jump to system setting, the system setting exit immediately.
  3. Use [[UIApplication sharedApplication]openURL:url options:@{}completionHandler:nil];It's crashed on iOS8 and iOS9,also,exit immediately on iOS10.

The question is can our app jump to system setting on iOS10? If yes.How?And for [[UIApplication sharedApplication]openURL:url options:@{}completionHandler:nil];what's the optionsmeans?We must code something for the options?

like image 936
无夜之星辰 Avatar asked Oct 09 '16 05:10

无夜之星辰


1 Answers

For some time now, apps have only been permitted to open their own settings pane in the settings app. There have been various settings URLs that have worked in the past, but recently Apple has been rejecting apps that use these URLS.

You can open your own application's settings:

if let url = URL(string:UIApplicationOpenSettingsURLString) {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

Or in Objective-C

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if (url != nil) {
    [[UIApplication sharedApplication] openURL:url options:[NSDictionary new] completionHandler:nil];
}

If you are targeting version of iOS earlier than 10 then you may prefer to use the older, deprecated, but still functional method:

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if (url != nil) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    [[UIApplication sharedApplication] openURL:url];
#pragma clang diagnostic pop
}
like image 185
Paulw11 Avatar answered Oct 10 '22 14:10

Paulw11