NSUbiquitousKeyValueStoreDidChangeExternallyNotification
根本没有被召唤?
var keyStore: NSUbiquitousKeyValueStore?
viewDidLoad{
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "ubiquitousKeyValueStoreDidChange:",
name: NSUbiquitousKeyValueStoreDidChangeExternallyNotification,
object: keyStore)
userDefinedLabelOne.text = keyStore?.stringForKey("userDefinedStringOne") <---this is changed
}
func ubiquitousKeyValueStoreDidChange(notification: NSNotification) {
println("Changed") <---- Not called
}
在iCloud功能中选择的键值存储
CloudKit共享数据确定
数据已保存到云中,但未调用更改通知
答案 0 :(得分:1)
退出iCloud帐户并重新开始正常工作
答案 1 :(得分:0)
看一看。这段代码适合我:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
prepareKeyValueStoreObserver()
return true
}
func syncKeyValueStore() {
let kvStore: NSUbiquitousKeyValueStore = NSUbiquitousKeyValueStore.defaultStore();
kvStore.synchronize()
}
func prepareKeyValueStoreObserver(){
let kvStore: NSUbiquitousKeyValueStore = NSUbiquitousKeyValueStore.defaultStore();
let notificationsCenter: NSNotificationCenter = NSNotificationCenter.defaultCenter()
notificationsCenter.addObserver(self, selector: "ubiquitousKeyValueStoreDidChange:", name: NSUbiquitousKeyValueStoreDidChangeExternallyNotification, object: kvStore)
syncKeyValueStore()
}