ios - 如何检索 Swift 中所有已安装键盘的列表?

标签 ios swift custom-keyboard

我正在尝试编写一个简单的函数来检查是否安装了特定的键盘。

到目前为止,这是我在函数中的内容:

func isCustomKeyboardEnabled() {

    let bundleID:NSString = "com.company.MyApp.Keyboard"

    let installedKeyboards = NSUserDefaults.standardUserDefaults().objectForKey("AppleKeyboards")

    println(installedKeyboards)

}

这是它在控制台中返回的内容:

Optional((
    "en_GB@hw=British;sw=QWERTY",
    "emoji@sw=Emoji",
    "com.nuance.swype.app.Global-Keyboard",
))

我很难检查我的 bundleID 是否在这个返回的对象中。我已经尝试了 for inif(contains(x,x)) 但它无法构建。任何帮助将非常感激。

最佳答案

Swift 2.0 解决方案:

func installedKeyboards(){
    if let installedKeyboard = NSUserDefaults.standardUserDefaults().objectForKey("AppleKeyboards") as? [String]{
        if installedKeyboard.contains("Your Unique Identifier"){
            print("Custom Keyboard Found")
        }else{
            print("Custom Keyboard Not Installed")
        }
    }  
}

关于ios - 如何检索 Swift 中所有已安装键盘的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28116369/

相关文章:

iphone - 本地通知“每天上午7:00”通知

arrays - 使用 "+="运算符连接到可选数组

ios - 包含自定义键盘扩展的应用必须具有隐私政策 URL

ios - UICollectionView 标题重叠

ios - 我如何从 HKHealthStore 中删除多个对象?

swift - 链接 UIView 动画(循环)

swift - 当分离到从 NSObject 继承的自定义类时,TransitioningDelegate 不适用于 UIPresentationController

ios - 如何在IOS自定义键盘应用程序扩展的InputView中嵌入WebView

swift - ios8 自定义键盘 : Why when I add UIImages does it not run on my device?

ios - 需要大量的 SkSpriteNode 和 CPU 使用率已经达到 90%