Xamarin.iOS 中的 iCloud 功能iCloud Capabilities in Xamarin.iOS

向应用程序添加功能通常需要其他预配设置。本指南将介绍 iCloud 功能所需的设置。Adding capabilities to an application often requires additional provisioning setup. This guide explains the setup needed for iCloud capabilities.

iCloud 向 iOS 用户提供了一种方便简单的方式来存储内容并在设备之间共享内容。iCloud provides iOS users with a convenient and simple way to store their content and share it between devices. 开发人员可采用四种方法使用 iCloud 来为用户提供存储方式:键值存储、UIDocument 存储、CoreData 和使用 CloudKit 直接为单个文件和目录提供存储。There are four ways that developers can use iCloud to provide a means of storage for their users: Key-Value storage, UIDocument Storage, CoreData, and using CloudKit directly to provide storage for Individual files and directories. 有关这些方面的详细信息,请参阅 iCloud 简介指南。For more information on these, refer to the Introduction to iCloud guide.

由于容器 的原因,将 iCloud 功能添加到应用程序与其他应用服务相比难度略大。Adding the iCloud capability to an application is slightly more difficult than other App Services because of containers. 容器在 iCloud 中用来存储应用的信息,并允许单个 iCloud 帐户中包含的所有信息被隔离,类似用户 iOS 设备上的沙盒。Containers are used in iCloud to store information for an app, and allow all information contained in a single iCloud account to be segregated – like the sandboxing on a user’s iOS device. 有关容器的详细信息,请参阅 CloudKit 简介指南。For more information on containers, refer to the Introduction to CloudKit guide.

重要

Apple 提供工具,用于帮助开发人员正确处理欧盟一般数据保护条例 (GDPR)。Apple provides tools to help developers properly handle the European Union's General Data Protection Regulation (GDPR).

开发人员中心Developer Center

通过开发人员中心预配新应用时需采取两个步骤:When provisioning a new app through the developer center there are two steps that need to be taken:

  1. 创建容器。Create a container.
  2. 创建具有 iCloud 功能的应用 ID 并向其添加容器。Create an App ID with the iCloud capability and add the container to it.
  3. 创建包含此应用 ID 的预配配置文件Create a Provisioning profile that includes this App ID

下述步骤可引导你完成这些步骤:The steps below will guide you through these steps:

  1. 浏览到 Apple 开发人员中心,然后转到“证书、标识符和配置文件”部分:Browse to the Apple Developer Center and go to the Certificates, Identifier, and Profiles section:

    Apple 开发人员中心主页

  2. 在“标识符” 下,选择“iCloud 容器” ,然后选择“+” 来创建新的容器:Under Identifiers select iCloud Containers, and then select the + to create a new container:

    iCloud 容器屏幕

  3. 为 iCloud 容器输入描述和唯一标识符Enter a Description and a unique Identifier for the iCloud container:

    iCloud 容器注册屏幕

  4. 按“继续” ,确保信息正确,然后按“注册” ,创建 iCloud 容器:Press Continue, ensure that the information is correct, and press Register to create the iCloud Container:

    iCloud 容器注册屏幕

若要创建新的应用 ID 并向其添加容器,请执行以下操作:To create a new App ID and add a container to it, do the following:

  1. 开发人员中心中的“标识符” 下,单击“应用 ID” :In the Developer Center, click on App IDs under Identifiers:

    开发人员中心中的标识符选择

  2. 选择“+” 按钮来添加新的应用 ID:Select the + button to add a new App ID:

    添加新的应用 ID 按钮

  3. 输入应用 ID 的名称,并赋予显式应用 IDEnter a Name for the App ID and give it an Explicit App ID:

    输入新的应用 ID 详细信息

  4. 在“应用服务” 下选择“iCloud” ,然后选择“包含 CloudKit 支持” :Under App Services select iCloud and choose Include CloudKit support:

    选择 iCloud 应用服务

  5. 选择“继续” ,然后选择“注册” 。Select Continue and then Register. 请注意,在确认屏幕上,iCloud 会以黄色符号显示已选择“可配置”的内容:Note that on the confirmation screen, iCloud will display with Configurable selected, with a yellow symbol:

    确认屏幕

  6. 返回应用 ID 列表,并选择刚才创建的应用 ID:Return to the list of App IDs and select the one that you have just created:

    选择应用 ID 屏幕

  7. 向下滚动到此展开部分的底部,然后单击“编辑” :Scroll down to the bottom of this expanded section and click Edit:

    编辑应用 ID

  8. 在列表中向下滚动到 iCloud,然后单击“编辑” 按钮:Scroll down the list to iCloud and click the Edit button:

    编辑 iCloud 应用 ID

  9. 选择要用于此应用 ID 的容器:Select the Container to use with this App ID:

    选择容器屏幕

  10. 确认容器分配,然后按“分配” 。Confirm the Container assignments, and press Assign.

现在此应用 ID 可用于生成或再生成新的预配配置文件,正如使用功能指南中所述。This App ID can now be used to generate, or to re-generate, a new provisioning profile, as described in the Working with Capabilities guide.

有关使用 iCloud 的详细信息,请参阅以下指南:For more information on using iCloud, refer to the following guides:

后续步骤Next Steps

下表列出了可能需要采取的其他步骤:The list below describes additional steps that may need to be taken:

  • 在应用中使用框架命名空间。Use the framework namespace in your app.
  • 将所需权利添加到应用。Add the required entitlements to your App. 有关所需权利以及添加方法的详细信息,请参阅使用权利指南。Information on the entitlements required and how to add them is detailed in the Working with Entitlements guide.
  • 在应用的“ iOS 捆绑包签名”中,确保“ 自定义权利”设置为“Entitlements.plist”。In the App's iOS Bundle Signing, ensure that the Custom Entitlements is set to Entitlements.plist. 对“调试”和“iOS 模拟器”生成来说,这不是默认设置。 __   This is not the default setting for Debug and iOS Simulator builds.

如果遇到与应用服务有关的问题,请参考主要指南的故障排除部分。If you encounter issues with app services, refer to the Troubleshooting section of the main guide.