11

How can we go directly to any of the below mentioned screens of iOS's settings app programmatically

Keyboard Screen enter image description here

iHulk
  • 4,869
  • 2
  • 30
  • 39

3 Answers3

17

UPDATE

As other users have pointed out this solution does not work anymore with iOS10. If anyone has an idea how to make it work in iOS10, please let us know.

Solution for iOS < 10:

To open the settings (of your own app) you can use the UIApplicationOpenSettingsURLString constant:

if let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString) {
    UIApplication.sharedApplication().openURL(settingsURL)
}

This was introduced in iOS 8, so you can use it on devices that run iOS8 or later. But this only opens the settings of your own app. Not the keyboard settings. And if your app does not have its own settings it only opens the Settings app on its main page.

In the old days (before iOS 5.1) you could open a settings URL and directly go to almost any subpage in the Settings app. Apple removed this feature in iOS 5.1.

However it seems to work again in iOS 8 and 9. It is not officially documented by Apple but it seems to work, although I not sure how reliable this is. It works on my iOS 9.1 iPhone but not in the Simulator.

So, with caution, you can try this to open the Keyboard Settings:

if let settingsURL = NSURL(string: "prefs:root=General&path=Keyboard") {
    UIApplication.sharedApplication().openURL(settingsURL)
}

Or go even deeper:

if let settingsURL = NSURL(string: "prefs:root=General&path=Keyboard/KEYBOARDS") {
    UIApplication.sharedApplication().openURL(settingsURL)
}

Edit: As iHulk mentioned in the comments you might have to add prefs to the URL schemes in your project's Info.plist file to make this work.

joern
  • 27,354
  • 7
  • 90
  • 105
  • Anyway to do that in iOS 8 as Fleksy does that in iOS 8 as well as in iOS 9. – iHulk Oct 28 '15 at 12:22
  • Have you tried it on iOS8? I don't have a iOS8 device at hand to test it. Maybe this also works on iOS 8 – joern Oct 28 '15 at 12:31
  • ok.. I was trying to do it simulator and it was not working, just tested on iOS 9 device and it is working. I'll check it on iOS 8 device and I'll let you know if it is working on it or not.. Thanks.. – iHulk Oct 28 '15 at 18:08
  • Yes, please let me know if it works on iOS8. Thanks! – joern Oct 28 '15 at 18:09
  • Hey @joern, I'm facing a strange issue. I'm able to go to settings screen using above code if Fleksy Keyboard is installed but if it is not installed then I'm not able to go to settings screen in my app. I've checked many times and it has baffled me, don't know what Fleksy has done.. – iHulk Nov 09 '15 at 10:10
  • Which path you talking about and what is happening when you try to open it? – joern Nov 09 '15 at 11:17
  • 2
    Nothing was happening, canOpenURL was returning false. Just found one Hack, if you add "prefs" in URL scheme then this URL starts working. – iHulk Nov 09 '15 at 11:22
  • Not working on iOS 9.3.1. I've added `prefs` to `LSApplicationQueriesSchemes` in the info.plist, still not working. – kelin Apr 05 '16 at 09:36
  • @kelin, you need to add `prefs` in `URL Schemes` of `Item 0` in `URL types` – dimpiax Jun 10 '16 at 12:32
  • 3
    That's right, does not work in iOS 10. Any solution yet? – Ahmet Akkök Oct 10 '16 at 14:07
10

As of iOS 10 "App-Prefs:root" should be used rather than "prefs:root". See below Objective C code. Tested this , code works fine but Apple may reject the app because of this.
Note : As pointed out this will work only on ios 10

 NSString *settingsUrl= @"App-Prefs:root=General&path=Keyboard";

 if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:settingsUrl] options:@{} completionHandler:^(BOOL success) {
    NSLog(@"URL opened");
    }];
}
Ankit J
  • 204
  • 2
  • 10
1

Latest message I got from Apple reviewers: Your app hosts extension(s) but it does not comply with the App Extension Programming Guide.

Specifically, your app brings users directly to the keyboards settings page rather than taking users to the specific settings page for your app. Please ensure that your app only brings users to your app settings page.

When I was redirecting to: prefs:root=General&path=Keyboard/KEYBOARDS

mamba
  • 11
  • 1