iCloud上的默认容器不适用于键值存储

时间:2014-10-31 01:28:00

标签: xcode6 icloud nsfilemanager key-value-store

在从Xcode 5到Xcode 6的变化中,以及在线更改到iCloud管理系统的某个地方,我无法将数据存储到iCloud中的键值存储中。更具体地说,现在,两者:

[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];

[NSFileManager defaultManager].ubiquityIdentityToken

现在两人都返回零。以前(至少)URLForUbiquityContainerIdentifier返回非零。

我尝试了这里给出的答案:Why ubiquityIdentityToken returns nil?https://devforums.apple.com/thread/229509,但没有快乐。

1 个答案:

答案 0 :(得分:1)

我找到了解决方法。我首先尝试使用Xcode 6的示例项目,目标是iOS6(我需要保持iOS6兼容性)。我在Capabilities下有这些设置:

enter image description here

似乎默认容器设置不适用于键值存储。也就是说,通过上述设置,ubiquityIdentityToken返回nil。

我接下来尝试检查CloudKit框,然后指定自定义容器。除了我的iOS6兼容性问题,这可能有用。 CloudKit无法在iOS6上运行。

然后我尝试检查iCloud Documents框(黑客攻击我的方式?)):

enter image description here

这导致ubiquityIdentityToken返回非零!当我在实际应用程序中进行此更改时,与此测试应用程序相反,我的键值存储再次起作用! (它也适用于iOS8.1)。

我的权利文件的相关部分现在是:

<key>com.apple.developer.icloud-container-identifiers</key>
<array>
    <string>iCloud.$(CFBundleIdentifier)</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
    <string>CloudDocuments</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
    <string>iCloud.$(CFBundleIdentifier)</string>
</array>
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>