【问题标题】:Sharing Common Key-Value Storage Between Multiple Apps Not Working在多个应用程序之间共享公共键值存储不起作用
【发布时间】:2013-04-17 01:32:40
【问题描述】:

我正准备推出我的一个应用的第二个版本。我将在以前版本的新捆绑 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 相同的键值存储中读取。但是,在执行简单测试时,它会失败。这是我的复制方式。

  1. 打开 MyApp 1.0。将布尔值“YES”写入键值存储键“InstalledVersion1”。

    NSUbiquitousKeyValueStore* store = [NSUbiquitousKeyValueStore defaultStore];
    [store setBool:YES forKey:@"InstalledVersion1"];
    
  2. 打开 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] 之后)。

【问题讨论】:

    标签: ios objective-c icloud key-value


    【解决方案1】:

    这个答案有点荒谬,但它适用于其他面临类似问题的人。

    这就是我所做的。

    1. 我的 iCloud 存储中有一个名为 CommonDocuments 的条目。我删除了它。
    2. 我打开了通过蜂窝数据传输 iCloud 文档。

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

    如果这两件事不适合你,我祝你好运。神速。

    【讨论】:

      猜你喜欢
      • 2018-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-15
      • 2017-07-27
      • 2018-01-01
      • 2014-06-04
      • 2021-02-25
      相关资源
      最近更新 更多