如何判断用户正在使用或切换到哪个第三方键盘?
我没有找到任何可用于检查此信息的通知或API。
答案 0 :(得分:0)
您无法知道安装了哪些键盘,也无法确定接下来要加载哪个键盘。
Apple的文档说明:
要求系统切换到另一个键盘,请致电 advanceToNextInputMode方法(..)系统选择合适的 “下一个”键盘;没有API来获取已启用的键盘列表 或者选择要切换到的特定键盘。
有关详细信息,请阅读Apple的Custom Keyboards API文档: https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html#//apple_ref/doc/uid/TP40014214-CH16-SW21
答案 1 :(得分: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;
}