【问题标题】:iOS 8 third party keyboard identificationiOS 8 第三方键盘识别
【发布时间】:2014-09-29 08:03:00
【问题描述】:

我如何知道用户正在使用或切换到哪个第三方键盘?

我没有找到任何可用于检查此信息的通知或 API。

【问题讨论】:

    标签: ios8 iphone-privateapi ios8-extension ios-keyboard-extension


    【解决方案1】:

    您无法知道安装了哪些键盘,也无法决定接下来要加载哪个键盘。

    Apple 的文档指出:

    要让系统切换到另一个键盘,请调用 AdvanceToNextInputMode 方法 (..) 系统选择合适的 “下一个”键盘;没有 API 来获取启用的键盘列表 或选择要切换到的特定键盘。

    如需更多信息,请阅读 Apple 的自定义键盘 API 文档: https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html#//apple_ref/doc/uid/TP40014214-CH16-SW21

    【讨论】:

    • 感谢您的回答。但我相信苹果一定有办法看到他们身边的键盘列表。只是想知道可能有一些 hacky 方法来实现这一点。
    • 如果有,您不能在提交的应用程序中使用它。这是违反规则的。
    【解决方案2】:

    有点晚了,但您可以获取设备上的活动键盘列表。所有键盘标识符都存储在UserDefaults 中,您可以通过以下方式获取它们:

    /**
    
     - Author:
     Panayot Panayotov
    
     - returns:
     True or False
    
     - Important:
     Result is returned immediately after non system identifier is found
    
     This method iterates through all public keyboard identifiers and
     evaluates a regex that matches system keyboards
     [
         "nb_NO@sw=QWERTY-Norwegian;hw=Automatic",
         "zh_Hant-Zhuyin@sw=Zhuyin;hw=Automatic",
         "ur@sw=Urdu;hw=Automatic",
         "zh_Hant-HWR@sw=HWR-Traditional",
         "zh_Hant-Pinyin@sw=Pinyin10-Traditional;hw=Automatic",
         "emoji@sw=Emoji"
     ]
     */
    -(BOOL)hasUnkownKeyboard {
    
        NSString * appleKeyboardsRegexp = @"^(?:[0-9a-zA-Z_\\-]+)(?:@sw|@hw)[0-9a-zA-Z_\\-\\-;=]*$";
        NSPredicate * appleKeyboardsTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", appleKeyboardsRegexp];
        NSArray *keyboards = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"AppleKeyboards"];
    
        for (NSString *keyboard in keyboards) {
            if(![appleKeyboardsTest evaluateWithObject:keyboard]){
                return YES;
            }
        }
    
        return NO;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-11-17
      • 2012-06-28
      • 1970-01-01
      • 2014-09-17
      • 1970-01-01
      • 2016-08-19
      • 1970-01-01
      • 2014-11-22
      • 1970-01-01
      相关资源
      最近更新 更多