I am writing a small universal game for iOS. The recorder will be synced across devices through the iCloud Key / Value store.
obtaining the latest grade:
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 }
maintaining a new record
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, ratings are not synchronized.
- no mistakes
- no glitches
- no null values
I always get the highest score from the current device, never achieved on others.
Could the reason be in itunesconnect or is there something wrong with my code? I use ipad and iphone for testing, both are logged into my icloud account.
I am logging changes for 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 }
but the function 'icloudKeyValueChanged' is never called.
The features of iCloud are all right, as it seems:

ios xcode ios8 swift icloud
Sebastian flรผckiger
source share