我如何知道用户是否从iPhone设置中删除了我的自定义键盘。
我的键盘被移除后,我必须管理一些用户默认值。
答案 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
}