【问题标题】:How to Open Keyboard's settings screen programmatically in iOS 10?如何在 iOS 10 中以编程方式打开键盘设置屏幕?
【发布时间】:2017-01-17 23:12:14
【问题描述】:

如何在 iOS 10 中以编程方式打开键盘的设置屏幕?

此代码在 iOS 10 中不起作用

NSURL *keyboardSettingsURL = [NSURL URLWithString: @"prefs:root=General&path=Keyboard/KEYBOARDS"];
    [[UIApplication sharedApplication] openURL:keyboardSettingsURL];

并添加了 URL Scheme

【问题讨论】:

    标签: ios ios10 custom-keyboard ios-extensions


    【解决方案1】:

    如果您还没有,您可能需要将 URL Scheme 添加到您的项目中。可以在Apple Q&A Reference 找到说明和更多详细信息。希望这会有所帮助!

    【讨论】:

    • 你试过用"prefs:root=General&path=Keyboard"代替"prefs:root=General&path=Keyboard/KEYBOARDS"吗?
    • "prefs:root=General&path=Keyboard" 也不起作用
    • 不幸的是,Apple 很可能已经从 iOS 10 中删除了这种类型的 URL 功能。根据一些 cmets here 的说法,Apple 似乎有拒绝应用程序的历史使用“prefs:*” URL,所以如果从 iOS 10 中删除它是有意义的
    • 提供的 URL 清楚地提到它只允许从键盘扩展中这样做。在所有其他情况下使用它都会导致应用被拒绝。
    • 我将这个用于键盘扩展应用程序
    【解决方案2】:

    iOS 10 中似乎禁用了此功能。我认为 https://developer.apple.com/library/content/qa/qa1924/_index.html 不再有效。我检查了几个顶级键盘应用程序,它们要么已更新为不再直接链接到首选项,要么有一个不起作用的按钮。

    【讨论】:

      【解决方案3】:

      在 iOS 10 中,需要一个新的 url。尝试使用测试两个 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;
          }
      }
      

      【讨论】:

        【解决方案4】:

        适用于 iOS 10+

        NSURL *keboardURL = [NSURL URLWithString: @"App-Prefs:root=General&path=Keyboard/KEYBOARDS"];
        [[UIApplication sharedApplication] openURL:keyboardURL];
        

        关键点:

        @"App-Prefs:root=General&path=Keyboard/KEYBOARDS"

        【讨论】:

        • 这适用于 iOS13。我试过但没有用。我们是否必须在 xcodeprojecte.g 中启用某些东西?网址类型?
        【解决方案5】:
        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];
             }
         }
        

        【讨论】:

          猜你喜欢
          • 2017-01-29
          • 2017-08-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-02-28
          • 1970-01-01
          相关资源
          最近更新 更多