1

当执行以下两行之一时,我的应用程序崩溃并显示“应用程序初始化文档选择器缺少 iCloud 权利”:

UIDocumentPickerViewController* documentPicker =
  [[UIDocumentPickerViewController alloc]
    initWithDocumentTypes:@[@"public.data"]
                   inMode:UIDocumentPickerModeImport];

UIDocumentMenuViewController *documentMenu =
  [[UIDocumentMenuViewController alloc]
    initWithDocumentTypes:@[@"public.data"]
                   inMode:UIDocumentPickerModeImport];

Document Picker Programming Guide声明“在您的应用程序可以使用文档选择器之前,您必须在 Xcode 中打开 iCloud Documents 功能。”

但是,我的应用程序不是用 Xcode 构建的:它是使用第三方工具(跨平台工具包,Marmalade)构建的,所以我不能这样做。

应该仍然可以手动打开此应用程序的 iCloud 文档功能——iCloud 中的开关只是自动执行该过程——但我尝试这样做并没有解决崩溃问题。

到目前为止我尝试过的

Xcode 显示了它在打开 iCloud 时执行的步骤:

  1. 将“iCloud”权利添加到您的 App ID
  2. 将“iCloud 容器”权利添加到您的 App ID
  3. 将“iCloud”权利添加到您的权利文件
  4. 链接 CloudKit.framework

我还找到了 Apple 的Entitlements Troubleshooting TechNote,它描述了可以用来检查以下步骤是否正确执行的步骤。

我在我的 App ID 上启用了 iCloud:

显示 iCloud 已启用的 App ID 的屏幕截图

我不确定这是否需要使用文档选择器的简单导入和导出操作,但我还设置了一个 id 的 iCloud 容器iCloud.com.[company].[app]

我已生成包含 iCloud 权利的更新配置文件:

显示 iCloud 服务已启用的配置文件的屏幕截图

我使用以下命令检查了下载的配置文件:

security cms -D -i /path/to/iOSTeamProfile.mobileprovision

它包括以下条目:

<key>com.apple.developer.icloud-services</key>
<string>*</string>
<key>com.apple.developer.icloud-container-environment</key>
<array>
  <string>Development</string>
  <string>Production</string>
</array>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
  <string>iCloud.com.[company].[app]</string>
</array>
<key>com.apple.developer.icloud-container-development-container-identifiers</key>
<array>
  <string>iCloud.com.[company].[app]</string>
</array>
<key>com.apple.developer.ubiquity-container-identifiers</key>
<array>
  <string>iCloud.com.[company].[app]</string>
</array>

Marmalade 使用此配置文件为应用程序生成权利文件。

我已经使用以下命令检查了生成的权利:

codesign -d --ent :- [App.app]

这给出了以下输出:

<?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>application-identifier</key>
  <string>[team-id].com.[company].[app]</string>
  <key>aps-environment</key>
  <string>development</string>
  <key>com.apple.developer.icloud-container-development-container-identifiers</key>
  <array>
    <string>iCloud.com.[company].[app]</string>
  </array>
  <key>com.apple.developer.icloud-container-environment</key>
  <array>
    <string>Development</string>
    <string>Production</string>
  </array>
  <key>com.apple.developer.icloud-container-identifiers</key>
  <array>
    <string>iCloud.com.[company].[app]</string>
  </array>
  <key>com.apple.developer.icloud-services</key>
  <string>*</string>
  <key>com.apple.developer.team-identifier</key>
  <string>[team-id]</string>
  <key>com.apple.developer.ubiquity-container-identifiers</key>
  <array>
    <string>iCloud.com.[company].[app]</string>
  </array>
  <key>com.apple.developer.ubiquity-kvstore-identifier</key>
  <string>[team-id].*</string>
  <key>get-task-allow</key>
  <true/>
  <key>keychain-access-groups</key>
  <array>
    <string>[team-id].com.[company].[app]</string>
  </array>
</dict>
</plist>

但是,每当调用函数时,应用程序仍然会崩溃。

我还找到了这个在 Marmalade 应用程序中设置 iCloud 的旧指南。大多数步骤似乎不再是必要/可能的,但我按照建议将application-identifier密钥添加到我的 Info.plist。

我还需要做什么才能将 iCloud Documents 功能添加到我的应用程序中?

4

1 回答 1

1

Marmalade.xcent通过复制配置文件中的“权利”来生成签署应用程序时使用的权利dict文件。

问题是由与未记录键关联的值引起的:

<key>com.apple.developer.icloud-services</key>
<string>*</string>

这在配置文件中似乎有效,但在登录应用程序时无效。用以下内容替换生成的那些元素,.xcent file然后重新签名应用程序解决了这个问题:

<key>com.apple.developer.icloud-services</key>
<array>
  <string>CloudDocuments</string>
</array>

(注意如果您还使用 CloudKit,您还需要CloudKit stringarray.)

在实践中,我们通过编辑 Marmalade 的sign_app.py脚本来修复此问题,以便在签署应用程序时使用预先准备好的文件(从我们使用 Xcode 构建的功能应用程序.xcent的目录中复制):DerivedData

在文件/Applications/Marmalade.app/Contents/s3e/deploy/plugins/iphone编辑第 557 行:

cmd += ['--entitlements', xcentfile.name]

...替换xcentfile.name为预先准备好的.xcent文件的路径。

于 2017-06-02T14:20:04.997 回答