7

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?

无夜之星辰
  • 5,426
  • 4
  • 25
  • 48

6 Answers6

11

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
}
Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • Is that to say,if I open my app own settings pane the Apple would not reject my app,if I use another way to go to settings,Apple would reject?And could you give me a Objective-c code please?I heard some people said that the `options` could not be null. – 无夜之星辰 Oct 09 '16 at 16:09
  • Sorry, I missed the tag. I have added Objective-C. You can open your own settings pane without fear of rejection but opening other preferences panes is not permitted. The options is not nil, it is empty – Paulw11 Oct 09 '16 at 19:50
  • @Paulw11, even i got the same issue, i had updated the code as per your suggestion if (@available(iOS 10.0, *)) { NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if (url != nil) { [[UIApplication sharedApplication] openURL:url options:[NSDictionary new] completionHandler:nil];} }else{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 }} – Arshad Shaik Oct 15 '18 at 09:36
  • @Paulw11 i am about to update to appstore for review. Please confirm. – Arshad Shaik Oct 15 '18 at 09:37
  • You should not be rejected for using the code in my answer (or the code you have shown). Make sure you don't have the `prefs:` anywhere in your app, even in a string you don't use as Apple will scan your app when you submit it and detect that string – Paulw11 Oct 15 '18 at 09:49
  • @Paulw11 yes i commented the earlier string. and in info URL scheme also i am not adding it. – Arshad Shaik Oct 15 '18 at 09:51
  • if (@available(iOS 10.0, *)) { NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if (url != nil) { [[UIApplication sharedApplication] openURL:url options:[NSDictionary new] completionHandler:nil]; } } – Arshad Shaik Oct 15 '18 at 09:52
  • else{ 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 } } – Arshad Shaik Oct 15 '18 at 09:52
  • If you have a rejection from Apple then you probably need to ask them for more details. You should also use the strings command and grep to confirm that the prefs: string doesn't appear in your binaries anywhere. – Paulw11 Oct 15 '18 at 09:54
  • @Paulw11, i searched for the prefs: string , it is been commented. – Arshad Shaik Oct 15 '18 at 09:56
  • i got this suggestion from apple, Next Steps:To resolve this issue, please revise your app to provide the associated functionality using public APIs or remove the functionality using the "prefs:root" or "App-Prefs:root" URL scheme.If there are no alternatives for providing the functionality your app requires, you can file an enhancement request. – Arshad Shaik Oct 15 '18 at 10:01
  • `UIApplication.openSettingsURLString` resolves to *"app-settings:"*, so it isn't the string the Apple is complaining about. You should scan your binary as I suggested. Try a clean/build to ensure that the old code isn't in a framework or something – Paulw11 Oct 15 '18 at 10:09
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181873/discussion-between-arshad-shaik-and-paulw11). – Arshad Shaik Oct 15 '18 at 10:10
6

Note:I use this method for a long time and everyting goes well,but today(2018-9-14),I had been rejected.

Here is my previous answer,do not use this method forever:

CGFloat systemVersion = [[UIDevice currentDevice].systemVersion floatValue];
if (systemVersion < 10) {
 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"]];
}else{
 [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"]
                                          options:[NSDictionary dictionary]
                                completionHandler:nil];
}

Now I use this way:

if (@available(iOS 10.0, *)) {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:[NSDictionary dictionary] completionHandler:nil];
} else {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
无夜之星辰
  • 5,426
  • 4
  • 25
  • 48
5

Note :- this solution will not be useful for ios10 onwards

Dont forget to add URL schemes :-

Go to Project settings --> Info --> URL Types --> Add New URL Schemes-->URL Schemes = prefs

after that Use this url :-

let settingUrl =  URL(string: "App-Prefs:root=Privacy&path=LOCATION")

And open using :-

      if #available(iOS 10.0, *) {
         UIApplication.shared.open(settingUrl) {
                (isOpen:Bool) in
                if !isOpen {
                    debugPrint("Error opening:\(settingUrl.absoluteString)")
                    // show error
                }
            }
      }else{ 
         if UIApplication.shared.canOpenURL(settingUrl) {
            UIApplication.shared.open(settingUrl, completionHandler: { (success) in
            print("Settings opened: \(success)") // Prints true

           })
         }
      }

Enjoy :)..this worked for me.

Ayush Yadav
  • 294
  • 5
  • 11
1

Thanks to this guy. I figure out this URL Scheme Prefs:root=Privacy&path=LOCATION is only available in Today Widget, but no use in containing app.

In Today Widget, you can try this:

[self.extensionContext openURL:[NSURL URLWithString:@"Prefs:root=Privacy&path=LOCATION"] completionHandler:nil];

More about system URL Schemes, you can see here.

This all I got. Hope it will help you.

yys
  • 551
  • 3
  • 11
1

You can also open your app's setting center by opening"App-Prefs:root=your app bundle id". This will be easy for user to change setting for your app.

sunkehappy
  • 8,970
  • 5
  • 44
  • 65
1

This works for me. iOS7 ~ iOS11

But if you are uing the iOS11, you can only jump to the app's setting page

        NSURL *url1 = [NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"];
        NSURL *url2 = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        if (@available(iOS 11.0, *)) {
            if ([[UIApplication sharedApplication] canOpenURL:url2]){
                [[UIApplication sharedApplication] openURL:url2 options:@{} completionHandler:nil];
            }
        } else {
            if ([[UIApplication sharedApplication] canOpenURL:url1]){
                if (@available(iOS 10.0, *)) {
                    [[UIApplication sharedApplication] openURL:url1 options:@{} completionHandler:nil];
                } else {
                    [[UIApplication sharedApplication] openURL:url1];
                }
            }
        }
NSKevin
  • 564
  • 8
  • 20