如何知道用户是否从iPhone设置中删除了我的自定义键盘?

时间:2016-08-21 05:31:46

标签: ios swift settings custom-keyboard

我如何知道用户是否从iPhone设置中删除了我的自定义键盘。

我的键盘被移除后,我必须管理一些用户默认值。

1 个答案:

答案 0 :(得分:1)

    static func isKeyboardInstalled() -> Bool {
        var isInstalled = false

        if let dict: AnyObject = NSUserDefaults.standardUserDefaults().dictionaryRepresentation() {
            let userDefaultsDictionary: Dictionary<String, AnyObject> = dict as! Dictionary<String, AnyObject>
            let keyboardArrayAnyObject: AnyObject? = userDefaultsDictionary["AppleKeyboards"]
            if let array: AnyObject = keyboardArrayAnyObject {
                let keyboardsArray: Array<String> = array as! Array<String>
                let appUrlSceme: String? = SystemUtils.applicationIdentifier()

                if let urlScheme = appUrlSceme {
                    for item in keyboardsArray {
                        if (item as NSString).containsString(urlScheme) {
                            isInstalled = true
                        }
                    }
                }
            }
        }

        return isInstalled
    }

    static func applicationIdentifier() -> String? {
        var appIdentifier: String? = nil

        if let identifier = NSBundle.mainBundle().objectForInfoDictionaryKey(kCFBundleIdentifierKey as String) as? String {
            appIdentifier = identifier
        }

        return appIdentifier
    }