【问题标题】:iCloud Key Value Storage Changes Not Called (NSUbiquitousKeyValueStoreDidChangeExternallyNotification)未调用 iCloud 键值存储更改 (NSUbiquitousKeyValueStoreDidChangeExternallyNotification)
【发布时间】:2015-09-29 04:09:55
【问题描述】:

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 共享数据正常

数据已保存到云端,但不会调用更改通知

【问题讨论】:

    标签: ios swift icloud key-value


    【解决方案1】:

    通过退出 iCloud 帐户并重新登录,一切都开始正常工作

    【讨论】:

    • 没有愚蠢的方式。这实际上奏效了。哇苹果,哇。谢谢芽
    【解决方案2】:

    看看。这段代码对我有用:

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

    【讨论】:

    • 我可能没有正确实现它,但这对我不起作用
    • 已编辑:重要的是要注意,当您的应用启动时,您应该立即调用同步,以便您的应用知道在启动时检查 iCloud Key-Value Store 的更改。
    • 是的,已完成并确认已通过日志记录同步
    猜你喜欢
    • 2014-12-21
    • 2016-10-19
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 2017-11-21
    • 2017-02-18
    • 2013-06-08
    • 1970-01-01
    相关资源
    最近更新 更多