1

如何判断用户正在使用或切换到哪个第三方键盘?

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

4

2 回答 2

0

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

苹果的文档指出:

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

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

于 2014-10-03T02:46:59.533 回答
0

有点晚了,但您可以获取设备上的活动键盘列表。所有键盘标识符都存储在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;
}
于 2018-05-11T13:54:27.393 回答