未调用iCloud密钥值存储更改(NSUbiquitousKeyValueStoreDidChangeExternallyNotification)

时间:2015-07-10 12:02:24

标签: ios swift icloud key-value

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 Key-Value-Store Synchronization issues (NSUbiquitousKeyValueStoreDidChangeExternallyNotification not called)

在iCloud功能中选择的键值存储

CloudKit共享数据确定

数据已保存到云中,但未调用更改通知

2 个答案:

答案 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()
}