Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing Common Key-Value Storage Between Multiple Apps Not Working

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.

  1. 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"];
    
  2. 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).

like image 802
dwlz Avatar asked Apr 23 '13 18:04

dwlz


1 Answers

The answer is sort of ridiculous, but here it goes for anyone else facing a similar issue.

Here's what I did.

  1. I had an entry in my iCloud storage called CommonDocuments. I deleted it.
  2. I turned on iCloud Document transfer over cellular data.

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.

like image 94
dwlz Avatar answered Oct 12 '22 14:10

dwlz