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

前端 未结 3 1707
北荒
北荒 2020-12-29 12:45

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

相关标签:
3条回答
  • 2020-12-29 13:26

    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.

    0 讨论(0)
  • 2020-12-29 13:30

    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");
        }];
    }
    
    0 讨论(0)
  • 2020-12-29 13:41

    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

    0 讨论(0)
提交回复
热议问题