如何在iOS 10中以编程方式打开键盘设置屏幕?
此代码在iOS 10中不起作用
NSURL *keyboardSettingsURL = [NSURL URLWithString: @"prefs:root=General&path=Keyboard/KEYBOARDS"];
[[UIApplication sharedApplication] openURL:keyboardSettingsURL];
并添加了URL Scheme
看起来iOS 10中已禁用此功能。我相信https://developer.apple.com/library/content/qa/qa1924/_index.html已不再有效。我检查了几个顶级键盘应用程序,它们已更新为不再具有指向首选项的直接链接,或者具有非工作按钮。
适用于iOS 10+
NSURL *keboardURL = [NSURL URLWithString: @"App-Prefs:root=General&path=Keyboard/KEYBOARDS"];
[[UIApplication sharedApplication] openURL:keyboardURL];
关键点:
@“的App-偏好设置:根=通用及路径=键盘/键盘”
如果您尚未将URL方案添加到项目中,则可能需要添加URL方案。在这个Apple Q&A Reference可以找到说明和更多细节。希望这可以帮助!
在iOS 10中,需要新的URL。尝试使用此代码测试两个网址:
NSArray* urlStrings = @[@"prefs:root=General&path=Keyboard/KEYBOARDS", @"App-Prefs:root=General&path=Keyboard/KEYBOARDS"];
for(NSString* urlString in urlStrings){
NSURL* url = [NSURL URLWithString:urlString];
if([[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL:url];
break;
}
}
For IOS-10 or higher,openURL is deprecated. use with completion handler like below.
NSString *settingsUrl= @"App-Prefs:root=General&path=Keyboard";
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0){
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:settingsUrl]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:settingsUrl] options:@{} completionHandler:nil];
}
}