【发布时间】:2014-09-29 08:03:00
【问题描述】:
我如何知道用户正在使用或切换到哪个第三方键盘?
我没有找到任何可用于检查此信息的通知或 API。
【问题讨论】:
标签: ios8 iphone-privateapi ios8-extension ios-keyboard-extension
我如何知道用户正在使用或切换到哪个第三方键盘?
我没有找到任何可用于检查此信息的通知或 API。
【问题讨论】:
标签: ios8 iphone-privateapi ios8-extension ios-keyboard-extension
您无法知道安装了哪些键盘,也无法决定接下来要加载哪个键盘。
Apple 的文档指出:
要让系统切换到另一个键盘,请调用 AdvanceToNextInputMode 方法 (..) 系统选择合适的 “下一个”键盘;没有 API 来获取启用的键盘列表 或选择要切换到的特定键盘。
如需更多信息,请阅读 Apple 的自定义键盘 API 文档: https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html#//apple_ref/doc/uid/TP40014214-CH16-SW21
【讨论】:
有点晚了,但您可以获取设备上的活动键盘列表。所有键盘标识符都存储在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;
}
【讨论】: