Open Keyboard's settings screen in iOS's settings app programmatically from another app

烂漫一生 提交于 2019-11-29 03:10:39

问题


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


回答1:


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.




回答2:


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");
    }];
}



回答3:


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



来源:https://stackoverflow.com/questions/33388317/open-keyboards-settings-screen-in-ioss-settings-app-programmatically-from-anot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!