iCloud键值存储同步问题(未调用NSUbiquitousKeyValueStoreDidChangeExternallyNotification) [英] iCloud Key-Value-Store Synchronization issues (NSUbiquitousKeyValueStoreDidChangeExternallyNotification not called)

查看:150
本文介绍了iCloud键值存储同步问题(未调用NSUbiquitousKeyValueStoreDidChangeExternallyNotification)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iOS编写一款小型通用游戏。
高分将通过iCloud Key / Value商店在设备上同步。

i am writing a small universal game for iOS. the highscore will be synched accross devices through an iCloud Key/Value store.

获得最新分数:

func retrieveHighestScore() -> Int64 {
        let iCloudScore: Int64 = NSUbiquitousKeyValueStore.defaultStore().longLongForKey(KeyValueKeyClassification.KeyHighscore.toRaw())
        let localScore: Int64 = Int64(NSUserDefaults.standardUserDefaults().integerForKey(KeyValueKeyClassification.KeyHighscore.toRaw()))
        var result: Int64 = 0

        if localScore > iCloudScore {
            storeNewHighscore(localScore)
            result = localScore
        } else {
            storeNewHighscore(iCloudScore)
            result = iCloudScore
        }
        return result
    }

存储新的高分

func storeNewHighscore(newScore: Int64) {
        NSUbiquitousKeyValueStore.defaultStore().setLongLong(newScore, forKey: KeyValueKeyClassification.KeyHighscore.toRaw())
        NSUserDefaults.standardUserDefaults().setInteger(Int(newScore), forKey: KeyValueKeyClassification.KeyHighscore.toRaw())
        if NSUbiquitousKeyValueStore.defaultStore().synchronize() {
            println("Synched Successfully")
        }
    }

由于某种原因,但得分并未同步。

for some reason however the scores are not synched.


  • 没有错误

  • 没有崩溃

  • no null值

我总是从当前设备获得最高分,而不是在其他设备上获得的分数。

i always get the highest score from the current device, never the one achieved on others.

原因可能在于itunesconnect还是我的代码有问题?我正在使用ipad和iphone进行测试,两者都登录到我自己的icloud帐户。

could the reason be within itunesconnect or is something wrong with my code? i am using an ipad and an iphone for testing, both logged in to my own icloud account.

我正在注册这样的更改:

i am registering for the changes like this:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

        NSNotificationCenter.defaultCenter().addObserver(self, selector: "icloudKeyValueChanged", name: NSUbiquitousKeyValueStoreDidChangeExternallyNotification, object: nil)
        if NSUbiquitousKeyValueStore.defaultStore().synchronize() {
            println("initial Synched Successfully")
        }

        return true
    }

但是从不调用函数'icloudKeyValueChanged'。

but the function 'icloudKeyValueChanged' is never called.

iCloud功能一切正常,看起来好像:

iCloud Capabilities all are ok as it seems:

推荐答案

我遇到了同样的问题。在我的设备上记录iCloud并重新登录,解决了这个问题: - )

I had the same problem. Logging of iCloud on my device, and logging back in, solved the problem :-)

这篇关于iCloud键值存储同步问题(未调用NSUbiquitousKeyValueStoreDidChangeExternallyNotification)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆