检测是否已安装自定义键盘

时间:2014-08-16 21:34:08

标签: ios objective-c ios8 ios-app-extension custom-keyboard

我已经阅读了文档,似乎找不到任何方法可以检测设置> general>键盘中是否安装了自定义键盘?

有人知道吗?

2 个答案:

答案 0 :(得分:8)

这可以通过hive> set hive.cli.print.header=true; hive> select * from tblemployee; OK id name gender salary departmentid 1 tomr male 40000 1 2 cats female 30000 2 3 john male 50000 1 4 james male 35000 3 5 sara female 29000 2 6 bens male 35000 1 7 saman female 30000 NULL 8 russel male 40000 2 9 valar female 30000 1 10 todd male 95000 NULL Time taken: 9.892 seconds 实现。只需检索NSUserDefaults对象,该对象包含用户为密钥" AppleKeyboards"安装的所有键盘的数组。然后检查数组是否包含键盘扩展名的包标识符。

standardUserDefaults

答案 1 :(得分:0)

这对我有用

func isKeyboardExtensionEnabled() -> Bool {
    guard let appBundleIdentifier = Bundle.main.bundleIdentifier else {
        fatalError("isKeyboardExtensionEnabled(): Cannot retrieve bundle identifier.")
    }

    guard let keyboards = UserDefaults.standard.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
}