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,693
  • 2
  • 22
  • 36
  • 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,481
  • 1
  • 27
  • 47
karthik
  • 611
  • 4
  • 14
  • 3
    'NSURL(string:"prefs:root=...' made my submission be rejected by Apple. If you are using this code you will probably get yours rejected too. – GuiSoySauce May 26 '16 at 21:25
  • @karthik So, what's your result? – werediver Jun 15 '16 at 16:04
  • @karthik I managed to get an app submitted with this code included last month. You can also get a more precise page within the Settings app for better UX http://pastebin.com/SrhqHjth – matt.writes.code Jun 17 '16 at 21:26
  • @sure Matt. I will try it again. – karthik Jun 17 '16 at 21:29
  • 3
    @karthik This solution is not working for iOS 10 . I am working on Xcode 8, swift 3. Any alternate solution? – Khadija Daruwala Sep 23 '16 at 04:29
  • will check and let you know the solution. – karthik Nov 04 '16 at 21:04
  • 1
    @LearnSwift From what i researched i concluded that directing user to the Settings app from your app is not allowed in iOS 10. Hence you could show some toast or alert telling the user to go to the settings app manually.. http://useyourloaf.com/blog/openurl-deprecated-in-ios10/ – Khadija Daruwala Nov 07 '16 at 05:00
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,166
  • 11
  • 32
  • 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