I'm preparing to launch a second version of one of my apps. I am going to be releasing this new version under a new bundle ID from the previous version. In the previous version, I used the iCloud key-value store to save some settings and other miscellaneous info. Here's my entitlements file for v1:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>get-task-allow</key>
<true/>
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>$(AppIdentifierPrefix)$(CFBundleIdentifier)</string>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)$(CFBundleIdentifier)</string>
</array>
</dict>
</plist>
After following the instructions at http://developer.apple.com/library/mac/#documentation/General/Conceptual/iCloudDesignGuide/Chapters/iCloudFundametals.html under "Configuring Common Key-Value Storage for Multiple Apps", here's what my v2 entitlements file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>$(TeamIdentifierPrefix)com.companyname.MyApp</string>
<key>get-task-allow</key>
<true/>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)$(CFBundleIdentifier)</string>
</array>
</dict>
</plist>
According to the docs, v2 should now read from the same key-value storage as the v1. However, when performing a simple test, it fails. Here's how I reproduce.
Open MyApp 1.0. Write a bool value of "YES" to key "InstalledVersion1" to the key-value store.
NSUbiquitousKeyValueStore* store = [NSUbiquitousKeyValueStore defaultStore];
[store setBool:YES forKey:@"InstalledVersion1"];
Open MyApp 2.0 and read this value from the store.
NSUbiquitousKeyValueStore* store = [NSUbiquitousKeyValueStore defaultStore];
[store synchronize];
NSLog(@"%@", [store dictionaryRepresentation]);
This prints {}
.
It should print something like { "InstalledVersion1" = 1; }
...but it's not.
What am I doing wrong? Do I just need to be a bit more patient for the store to synchronize?
Device logs if you're interested: https://gist.github.com/dlo/688f187c75fd1b1fdc78 (after running p (void)[[NSUbiquitousKeyValueStore defaultStore] _printDebugDescription]
in the debugger).
The answer is sort of ridiculous, but here it goes for anyone else facing a similar issue.
Here's what I did.
After three days of trying everything, it turns out that an obscure item in iCloud storage and seemingly unrelated setting are what fixed the problem.
If these two things don't do it for you, I wish you luck. Godspeed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With