简体   繁体   English

从另一个应用程序以编程方式在iOS的设置应用程序中打开键盘的设置屏幕

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

How can we go directly to any of the below mentioned screens of iOS's settings app programmatically 我们如何以编程方式直接进入iOS设置应用程序的任何下面提到的屏幕

键盘屏幕 在此输入图像描述

UPDATE UPDATE

As other users have pointed out this solution does not work anymore with iOS10. 正如其他用户指出的那样,这个解决方案不再适用于iOS10。 If anyone has an idea how to make it work in iOS10, please let us know. 如果有人知道如何让它在iOS10中运行,请告诉我们。

Solution for iOS < 10: iOS <10的解决方案:

To open the settings (of your own app) you can use the UIApplicationOpenSettingsURLString constant: 要打开(您自己的应用程序)的设置,您可以使用UIApplicationOpenSettingsURLString常量:

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. 这是在iOS 8中引入的,因此您可以在运行iOS8或更高版本的设备上使用它。 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. 在过去(iOS 5.1之前),您可以打开设置URL并直接转到“设置”应用中的任何子页面。 Apple removed this feature in iOS 5.1. Apple在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. 然而它似乎在iOS 8和9中再次起作用。它没有被Apple正式记录,但似乎有效,但我不确定这是多么可靠。 It works on my iOS 9.1 iPhone but not in the Simulator. 它适用于我的iOS 9.1 iPhone,但不适用于模拟器。

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. 编辑:正如iHulk在评论中提到的,您可能必须在项目的Info.plist文件中为URL方案添加prefs才能使其工作。

As of iOS 10 "App-Prefs:root" should be used rather than "prefs:root". 从iOS 10开始,应该使用“App-Prefs:root”而不是“prefs:root”。 See below Objective C code. 见下面的Objective C代码。 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 注意:正如所指出的,这仅适用于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");
    }];
}

Latest message I got from Apple reviewers: Your app hosts extension(s) but it does not comply with the App Extension Programming Guide. 我从Apple评论者处得到的最新消息:您的应用程序托管扩展程序,但它不符合App Extension编程指南。

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 当我重定向到:prefs:root = General&path = Keyboard / KEYBOARDS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM