4
A
回答
4
感谢Guy的评论,有更好的方法来做到这一点。我已经更新了我自己的代码使用以下命令:
NSArray *keyboards = [UITextInputMode activeInputModes];
for (UITextInputMode *mode in keyboards) {
NSString *name = mode.primaryLanguage;
if ([name hasPrefix:@"zh-Han"]) {
// One of the Chinese keyboards is installed
break;
}
}
斯威夫特:(注意:一个变通方法下的iOS 9.x的残破由于糟糕的声明UITextInputMode activeInputModes
见this answer。)
let keyboards = UITextInputMode.activeInputModes()
for var mode in keyboards {
var primary = mode.primaryLanguage
if let lang = primary {
if lang.hasPrefix("zh") {
// One of the Chinese keyboards is installed
break
}
}
}
老办法:
我不知道这是在App Store应用允许或没有,但你可以这样做:
NSArray *keyboards = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleKeyboards"];
for (NSString *keyboard in keyboards) {
if ([keyboard hasPrefix:@"zh_Han"]) {
// One of the Chinese keyboards is installed
}
}
这是可能的,如果用户仅拥有默认键盘为自己的语言环境,也不会有对AppleKeyboards
键的条目。在这种情况下,您可能想要检查用户的区域设置。如果语言环境是针对中国的,那么你应该认为他们有中文键盘。
-1
这段代码是真正有用的,我来识别键盘延长被激活或者未设备设置从父应用程序本身:
//Put below function in app delegate...
public func isKeyboardExtensionEnabled() -> Bool {
guard let appBundleIdentifier = NSBundle.mainBundle().bundleIdentifier else {
fatalError("isKeyboardExtensionEnabled(): Cannot retrieve bundle identifier.")
}
guard let keyboards = NSUserDefaults.standardUserDefaults().dictionaryRepresentation()["AppleKeyboards"] as? [String] else {
// There is no key `AppleKeyboards` in NSUserDefaults. That happens sometimes.
return false
}
let keyboardExtensionBundleIdentifierPrefix = appBundleIdentifier + "."
for keyboard in keyboards {
if keyboard.hasPrefix(keyboardExtensionBundleIdentifierPrefix) {
return true
}
}
return false
}
// Call it from below delegate method to identify...
func applicationWillEnterForeground(_ application: UIApplication) {
if(isKeyboardExtensionEnabled()){
showAlert(message: "Hurrey! My-Keyboard is activated");
}
else{
showAlert(message: "Please activate My-Keyboard!");
}
}
func applicationDidBecomeActive(_ application: UIApplication) {
if(isKeyboardExtensionEnabled()){
showAlert(message: "Hurrey! My-Keyboard is activated");
}
else{
showAlert(message: "Please activate My-Keyboard!");
}
}
相关问题
- 1. 获取自定义键盘中isSticky键的当前状态
- 2. 获取Vim中设置的当前值
- 3. 获取当前的键盘布局的语言在JavaScript
- 4. 当viewDidLoad设置textField可编辑/启用键盘
- 5. 获取ICU的当前区域设置
- 6. 获取当前活动的键盘语言作为NSLocale
- 7. iOS:如何获取当前可见的键盘类型?
- 8. 如何获取当前键盘布局的代码页?
- 9. 获取当前PHP安装设置
- 10. 获取当前默认maxConcurrentSessions设置
- 11. 无法获取当前设备位置
- 12. 如何在应用程序启动时获取当前位置?
- 13. 获取当前在C++中设置的全局语言环境?
- 14. 如何获取在Unix中更改当前键盘布局的事件?
- 15. 从gps启用设备获取当前的经纬度
- 16. 在GPS中获取当前位置?
- 17. 在mysql表中获取当前位置
- 18. iOS8键盘扩展获取当前上下文
- 19. 软键盘设置
- 20. 如何在Xamarin中获取/设置当前音量水平?
- 21. 在键盘上获取MotionEvent
- 22. 在设置包中关闭键盘/数字键盘iOS
- 23. 在Android自定义键盘中设置键盘模式
- 24. Android获取当前位置
- 25. android获取当前位置
- 26. 获取当前位置android
- 27. 获取当前位置
- 28. 获取当前位置
- 29. 获取当前位置
- 30. 打开键盘时获取键盘高度或顶部位置
伟大的作品,谢谢。 用于检查当前语言的代码是 '如果([[[NSLocale preferredLanguages] objectAtIndex:0] hasPrefix:@ “ZH”]){// 当前语言是中国 }' – martinjbaker 2013-03-15 08:32:00
该解决方案是哈克。你们应该检查出http://stackoverflow.com/questions/12816325/applekeyboards-in-ios6 – 2014-02-27 13:06:48
@GuyKogus是的,这可能有点“黑客”,但它的工作原理。您链接到的问题不回答这个问题。您的链接用于确定当前键盘,而不是查看给定的键盘是否可用。 – rmaddy 2014-02-27 15:12:42