Xamarin.iOS 的 iCloud 功能

為應用程式新增功能通常需要額外的佈建設定。 本指南說明 iCloud 功能所需的設定。

iCloud 提供一個簡便的方式,可供 iOS 使用者儲存其內容及在裝置之間共用該內容。 有四種方法可供開發人員使用 iCloud 來為其使用者提供儲存方式:「機碼/值」儲存體、UIDocument 儲存體、CoreData,以及直接使用 CloudKit 來為個人檔案和目錄提供儲存體。 如需有關這些方法的詳細資訊,請參閱 iCloud 簡介指南。

由於「容器」因素,因此為應用程式新增 iCloud 功能比新增其他「應用程式服務」略為困難。 在 iCloud 中會使用容器來儲存應用程式的資訊,並可隔離單一 iCloud 帳戶中包含的所有資訊 – 就像使用者 iOS 裝置上的沙箱一樣。 如需有關容器的詳細資訊,請參閱 CloudKit 簡介指南。

重要

Apple 提供工具協助開發人員適當地處理歐盟一般資料保護規定 (GDPR)。

Developer Center \(開發人員中心\)

透過開發人員中心佈建新的應用程式時,需要進行兩個步驟:

  1. 建立容器。
  2. 建立具有 iCloud 功能的 App ID (應用程式識別碼),然後在其中新增容器。
  3. 建立包含此 App ID (應用程式識別碼) 的佈建設定檔

下列步驟將引導您完成這些步驟:

  1. 瀏覽至 Apple Developer Center \(Apple 開發人員中心\),然後移至 [Certificates, Identifier, and Profiles] \(憑證、識別碼及設定檔\) 區段:

    Apple Developer Center main page

  2. 在 [Identifiers] \(識別碼\) 底下,選取 [iCloud Containers] \(iCloud 容器\),然後選取 []+ 來建立新的容器:

    iCloud Container screen

  3. 輸入 iCloud 容器的 [Description] \(描述\) 和唯一 [Identifier] \(識別碼\)

    Screenshot shows Registering an i Cloud container.

  4. 按 [Continue] \(繼續\),確定資訊正確,然後按 [註冊] 以建立 iCloud Container (iCloud 容器):

    Screenshot shows Confirm your i Cloud container.

若要建立新的 App ID (應用程式識別碼) 並為其新增容器,請執行下列動作:

  1. Developer Center \(開發人員中心\) 中,按一下 [Identifiers] \(識別碼\) 底下的 [App IDs] \(應用程式識別碼\)

    Identifier Section in Developer Center

  2. 選取 []+ 按鈕來新增 App ID (應用程式識別碼):

    Add new App ID button

  3. 輸入 App ID (應用程式識別碼) 的 [Name] \(名稱\),並為它提供 [Explicit App ID] \(明確的應用程式識別碼\)

    Enter new App ID details

  4. 在 [App Services] \(應用程式服務\) 底下,選取 [iCloud],然後選擇 [Include CloudKit support] \(包含 CloudKit 支援\)

    Select iCloud app services

  5. 選取 [Continue] \(繼續\),然後選取 [Register] \(註冊\)。 請注意,在確認畫面上,iCloud 的 [Configurable] \(可設定\) 會顯示成已選取 (帶有黃色符號):

    Confirmation screen

  6. 返回 App ID (應用程式識別碼) 清單,然後選取您剛才建立的應用程式識別碼:

    Select App ID screen

  7. 向下捲動到這個已展開區段的底部,然後按一下 [Edit] \(編輯\)

    Edit App ID

  8. 將清單向下捲動到 iCloud,然後按一下 [Edit] \(編輯\) 按鈕:

    Edit iCloud App ID

  9. 選取要與此 App ID (應用程式識別碼) 搭配使用的 Container (容器):

    Select container screen

  10. 確認 Container (容器) 指派項目,然後按 [Assign] \(指派\)

此 App ID (應用程式識別碼) 現在已可用來產生 (或重新產生) 新的佈建設定檔,如使用功能指南所述。

如需有關使用 iCloud 的詳細資訊,請參閱下列指南:

後續步驟

以下清單說明可能需要進行的額外步驟:

  • 在您的應用程式中使用架構命名空間。
  • 為您的應用程式新增必要的權利。 如需有關所需權利及如何新增這些權利的詳細資訊,請參閱使用權利指南。
  • 在應用程式的 [iOS 套件組合簽署] 中,確定 [自訂權利] 已設定為 Entitlements.plist 這「不是」「偵錯」和「iOS 模擬器」組建的預設設定。

如果您在應用程式服務方面遇到問題,請參閱主要指南的疑難排解一節。