title: Sharing Common Key-Value Storage Between Multiple Apps Not Working
body: <p>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:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
  &lt;plist version="1.0"&gt;
  &lt;dict&gt;
       &lt;key&gt;get-task-allow&lt;/key&gt;
       &lt;true/&gt;
       &lt;key&gt;com.apple.developer.ubiquity-kvstore-identifier&lt;/key&gt;
       &lt;string&gt;$(AppIdentifierPrefix)$(CFBundleIdentifier)&lt;/string&gt;
       &lt;key&gt;keychain-access-groups&lt;/key&gt;
       &lt;array&gt;
            &lt;string&gt;$(AppIdentifierPrefix)$(CFBundleIdentifier)&lt;/string&gt;
       &lt;/array&gt;
  &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>
  
  <p>After following the instructions at <a href="http://developer.apple.com/library/mac/#documentation/General/Conceptual/iCloudDesignGuide/Chapters/iCloudFundametals.html">http://developer.apple.com/library/mac/#documentation/General/Conceptual/iCloudDesignGuide/Chapters/iCloudFundametals.html</a> under "Configuring Common Key-Value Storage for Multiple Apps", here's what my v2 entitlements file looks like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
  &lt;plist version="1.0"&gt;
  &lt;dict&gt;
       &lt;key&gt;com.apple.developer.ubiquity-kvstore-identifier&lt;/key&gt;
       &lt;string&gt;$(TeamIdentifierPrefix)com.companyname.MyApp&lt;/string&gt;
       &lt;key&gt;get-task-allow&lt;/key&gt;
       &lt;true/&gt;
       &lt;key&gt;keychain-access-groups&lt;/key&gt;
       &lt;array&gt;
            &lt;string&gt;$(AppIdentifierPrefix)$(CFBundleIdentifier)&lt;/string&gt;
       &lt;/array&gt;
  &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>
  
  <p>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.</p>
  
  <ol>
  <li><p>Open MyApp 1.0. Write a bool value of "YES" to key "InstalledVersion1" to the key-value store.</p>
  
  <pre><code>NSUbiquitousKeyValueStore* store = [NSUbiquitousKeyValueStore defaultStore];
  [store setBool:YES forKey:@"InstalledVersion1"];
  </code></pre></li>
  <li><p>Open MyApp 2.0 and read this value from the store.</p>
  
  <pre><code>NSUbiquitousKeyValueStore* store = [NSUbiquitousKeyValueStore defaultStore];
  [store synchronize];
  NSLog(@"%@", [store dictionaryRepresentation]);
  </code></pre></li>
  </ol>
  
  <p>This prints <code>{}</code>.</p>
  
  <p>It should print something like <code>{ "InstalledVersion1" = 1; }</code></p>
  
  <p>...but it's not.</p>
  
  <p>What am I doing wrong? Do I just need to be a bit more patient for the store to synchronize?</p>
  
  <p>Device logs if you're interested: <a href="https://gist.github.com/dlo/688f187c75fd1b1fdc78">https://gist.github.com/dlo/688f187c75fd1b1fdc78</a> (after running <code>p (void)[[NSUbiquitousKeyValueStore defaultStore] _printDebugDescription]</code> in the debugger).</p>