ios – 在多个应用程序之间共享公共键值存储不起作用

我正准备推出其中一个应用程序的第二个版本.我将在以前版本的新捆绑ID下发布此新版本.在之前的版本中,我使用iCloud键值存储来保存一些设置和其他杂项信息.这是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>

按照“配置多个应用程序的公共键值存储”下的http://developer.apple.com/library/mac/#documentation/General/Conceptual/iCloudDesignGuide/Chapters/iCloudFundametals.html中的说明操作后,这是我的v2权利文件的样子:

<?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>

根据文档,v2现在应该从与v1相同的键值存储中读取.但是,在执行简单测试时,它会失败.这是我如何重现.

>打开MyApp 1.0.将键入“InstalledVersion1”的bool值“YES”写入键值存储区.

NSUbiquitousKeyValueStore* store = [NSUbiquitousKeyValueStore defaultStore];
[store setBool:YES forKey:@"InstalledVersion1"];

>打开MyApp 2.0并从商店中读取此值.

NSUbiquitousKeyValueStore* store = [NSUbiquitousKeyValueStore defaultStore];
[store synchronize];
NSLog(@"%@",[store dictionaryRepresentation]);

这打印{}.

它应该打印像{“InstalledVersion1”= 1; }

……但事实并非如此.

我究竟做错了什么?我只需要更耐心地让商店同步吗?

设备日志如果您感兴趣:https://gist.github.com/dlo/688f187c75fd1b1fdc78(在调试器中运行p(void)[[NSUbiquitousKeyValueStore defaultStore] _printDebugDescription]之后).

解决方法

答案有点荒谬,但在这里,任何其他人都面临着类似的问题.

这就是我做的.

>我的iCloud存储中有一个名为CommonDocuments的条目.我已经把它删了.
>我打开了通过蜂窝数据进行iCloud Document传输.

经过三天的尝试,事实证明,iCloud存储中的一个不起眼的项目和看似无关的设置是解决问题的原因.

如果这两件事不适合你,我祝你好运.一帆风顺.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...