My problem is simple:
I'm now developing Cocoa application which stores data in iCloud (key value store). In order to test iCloud synchronisation I've build a simple iOS app, and installed it in my device.
I did iCloud initialisation in cocoa app:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dataUpdatedFromCloud:) name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification object:[NSUbiquitousKeyValueStore defaultStore]];
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
and selector:
+(void)dataUpdatedFromCloud:(NSNotification *)notification {
NSLog(@"dataUpdatedFromCloud: %@", [[NSUbiquitousKeyValueStore defaultStore] objectForKey:@"theKey"]);
}
in order to catch data when it comes from iCloud.
I do everything same in iOS app, with extra action when I store data in NSUbiquitousKeyValueStore:
// Script 1
[[NSUbiquitousKeyValueStore defaultStore] setDictionary:@{@"id":@1} forKey:@"theKey"];
My testing scenario is:
- Run cocoa application in Xcode
- Run iOS app in my device
- In iOS app I have a button, which calls Script 1
- Here I expect dataUpdatedFromCloud is called in 10-20 seconds on Cocoa app, but it doesn't!!!
Am I doing everything correct, or maybe I understood something incorrectly?
Well, probably, but reasons it might fail include:
ubiquityIdentityToken
in both apps to verify this.@1
as the value, it's entirely possible that the value has already been received and that new attempts aren't changing anything. For testing, it might help to replace@1
with something like@([NSDate timeIntervalSinceReferenceDate])
just to make sure you get a different value every time.