1

I recently have an app summited to the app store and they refused to approve the following code I used open phone settings:

let url:NSURL! = NSURL(string : "prefs:root=")
    UIApplication.sharedApplication().openURL(url)

So I got the following code (How do i open phone settings when a button is clicked ios) and got it approved:

UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!)

Unfortunately it does not do what I really need as it opens my application settings sometimes and other times it opens the phone settings.

And I need something to open just & only the phone settings instead.

Community
  • 1
  • 1
GuiSoySauce
  • 1,763
  • 3
  • 24
  • 37
  • 2
    There is no approved way to open the Settings app except for `UIApplicationOpenSettingsURLString`. – rmaddy May 23 '16 at 20:25
  • Try with http://stackoverflow.com/questions/5655674/opening-the-settings-app-from-another-app and http://stackoverflow.com/questions/28152526/how-do-i-open-phone-settings-when-a-button-is-clicked-ios – karthik May 23 '16 at 21:07
  • @maddy, that is ok if 'UIApplicationOpenSettingsURLString' is the only way to open settings. But it is weird that it sometimes opens the phone setting app at root and sometimes opens the app settings inside the phone settings. Sounds more like a bug to me as there is no rule for when to open which. – GuiSoySauce May 25 '16 at 02:27
  • @karthik, thanks for the tip but does not really solves the question as I am already using what is in there but getting an error that is not covered by the post you refer to. – GuiSoySauce May 25 '16 at 02:28
  • Check this: http://stackoverflow.com/questions/5655674/opening-the-settings-app-from-another-app/37439140#37439140 – guyromb May 25 '16 at 13:47

2 Answers2

1

This will open the Settings page like shown below.

UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root=Settings")!)

Screenshot

But unfortunately, use of this code in your application leads to rejection on the review process (see the comments).

werediver
  • 4,667
  • 1
  • 29
  • 49
karthik
  • 621
  • 4
  • 14
1

In iOS 10, "prefs" must be replaced with "App-Prefs". You can then use this code which tests over all the possible urls.

NSArray* urlStrings = @[@"prefs:root=<your_path>", @"App-Prefs:root=<your_path>"];
for(NSString* urlString in urlStrings){
    NSURL* url = [NSURL URLWithString:urlString];
    if([[UIApplication sharedApplication] canOpenURL:url]){
        [[UIApplication sharedApplication] openURL:url];
        break;
    }
}
Drico
  • 1,284
  • 15
  • 33
  • Is this legit? Successful app submission doesn't mean that this is legit. It may fail eventually in the future.. can't find proofs :( – Stas Mar 23 '17 at 07:33
  • 1
    Using 'App-Prefs' is not allowed and using it may result in rejection of the app. – Tejas K Jul 25 '18 at 04:23