iCloud快速部署

Enabling CloudKit in Your App

CloudKit is an app service available only to apps distributed through the App Store and Mac App Store. CloudKit requires additional configuration in your Xcode project. Your app must be provisioned and code signed to access CloudKit. To avoid code signing issues, enable CloudKit using the Capabilities pane in Xcode. There should be no need for you to edit entitlements directly in Xcode or Member Center.

在你的應用中安裝CloudKit

CloudKit是一個通過app Store和Mac app Store下載的應用程序的服務。CloudKit 需要在Xcode項目中進行額外的配置。你的App必須配置好並用代碼訪問CloudKit。爲了避免代碼簽名問題,使用Xcode中功能面板啓用CloudKit。你應該沒有必要直接需要權利在Xcode或會員中心進行編輯。

About Containers and Databases

Multiple apps and users have access to iCloud, but data is segregated and encapsulated in partitions called containers. The containers belonging to your apps cannot be accessed by apps from another developer. However, your apps can share containers. Multiple apps can share the same container, and one app can use multiple containers. There’s one default container per app, but you can create additional custom containers. The identifier for the default container matches the app’s bundle ID. The other container IDs you specify need to be unique across all developer accounts. Containers can’t be deleted.

關於容器和數據庫
多個應用程序和用戶可以訪問到iCloud,但數據分開,並封裝在各個分區,這些分區稱爲容器。屬於您應用程序的容器不能從其他開發人員的應用程序進行訪問。然而,你的應用程序可以共享自己的容器。多個應用程序可以共用相同的容器中,且一個應用程序可以使用多個容器。每個應用擁有一個默認的容器,但您可以創建其他自定義容器。默認容器的標識符與應用程序的包ID相匹配。您指定的其他容器的ID必須在所有開發者賬號裏是唯一的。容器不能被刪除。

An app has access to both a public and private database in each container. The public database is for storing user and app data that is shared between all instances of the app. By default, all users can read the public database, but they need to enter iCloud credentials to write to the public database. There’s a private database for each user of your app, but the app only has access to the private database of the current user. The user has to enter iCloud credentials for the app to read and write to the private database.
一個應用程序可以訪問每個容器的公共或者私人數據庫。公共數據庫是用於存儲應用中所有實例之間的用戶和應用數據。默認情況下,所有用戶都可以讀取公共數據庫,但他們需要輸入iCloud的憑據來訪問公共數據庫。有一個私人數據庫提供給應用程序的每個用戶,但應用程序只能訪問當前用戶的私人數據庫。用戶必須替應用輸入iCloud的憑據來讀取和寫入私人數據庫。



Setup  設置步驟

To perform all the steps in this document, you need:   要實現此文檔中的所有步驟,你需要:

  • A Mac computer with Xcode 6 or later installed               有Xcode6及之後版本的Mac

  • For the best experience, the latest OS X and Xcode releases installed    最好是最新的OSX和Xcode

  • An Xcode project that builds without errors沒有錯誤地構建一個Xcode項目

  • Membership in either the iOS Developer Program or the Mac Developer ProgramiOS或Mac應用開發者會員,有開發者帳號

  • Permission to create code signing and provisioning assets in Member Center    

    允許創建代碼簽名和在會員中心配置資產

Verify that you have performed these tasks before you begin using CloudKit. For step-by-step instructions, read App Distribution Quick Start.

Task

../Art/checkbox_checked_2x.png

Join the iOS Developer Program or Mac Developer Program.

../Art/checkbox_checked_2x.png

Create an Xcode project that builds and runs.

../Art/checkbox_checked_2x.png

Add your Apple ID to Accounts preferences.

../Art/checkbox_checked_2x.png

Create your team provisioning profile:

  • For Mac apps, choose Mac App Store as the signing identity.

  • Select your team from the Team pop-up menu.

  • Click Fix Issue.

../Art/checkbox_checked_2x.png

For Mac apps, enable App Sandbox in the Capabilities pane.

If you successfully complete the preceding tasks, the error message and Fix Issue button below the Team pop-up menu in the General pane disappears. The screenshot below shows the General pane for an iOS app when the code signing assets are successfully created.



Enable iCloud and Select CloudKit      啓用iCloud並選擇CloudKit


CloudKit is one of three app services provided by iCloud. The other iCloud app services—key-value storage and iCloud documents—also appear in the iCloud settings in Xcode. To use CloudKit, you first enable iCloud and then select the CloudKit service.

Important: When you select CloudKit, Xcode creates a default container ID based on the bundle ID. Because you can’t delete iCloud containers, verify that your bundle ID is correct in the General pane in Xcode before selecting CloudKit. To change your bundle ID, read Set the Bundle ID inApp Distribution Quick Start.

CloudKit是iCloud中提供的三種應用服務之一。其他的iCloud應用程序服務:鍵 - 值存儲和iCloud的文件存儲,也在Xcode中的iCloud設置出現。要使用CloudKit,你首先啓用的iCloud,然後選擇CloudKit服務。
重要提示:當您選擇CloudKit,Xcode創建基於包ID的默認容器ID。因爲你不能刪除iCloud的容器,驗證您的包ID是在Xcode中選擇CloudKit前的常規窗格中正確的。如果要改變你的包ID,請讀...


To enable iCloud and select CloudKit      啓動iCloud然後選擇CloudKit

  1. In the Capabilities pane, select the switch in the iCloud row.

    Xcode provisions your app to use iCloud. (Key-value storage is enabled by default.) 在功能窗格中,打開iCloud的開關(鍵-值存儲模式會默認打開)

  2. Select the CloudKit checkbox. 

    Xcode creates a default CloudKit container based on the bundle ID and adds the CloudKit framework to your project. 選擇CloudKit複選框,Xcode會創建基於包ID的默認CloudKit數據庫並且將CloudKit framework添加到你的項目中


Your app can now store data and documents in iCloud.


Access CloudKit Dashboard

Use CloudKit Dashboard to manage your CloudKit container schema and records. The schema describes the organization of records, attributes, and relationships in a database. A record is an instance of a record type. In a relational database, a record type corresponds to a table and a record corresponds to a row in a table.

訪問CloudKit儀表板


使用CloudKit儀表板來管理您的CloudKit容器的模式和記錄。該模式描述了數據庫的記錄,屬性和關係的組織。記錄是一個記錄類型的實例。在關係數據庫中,記錄類型對應於一個表 ,一個記錄對應於一個表中的行。

To sign in to CloudKit Dashboard

  1. In the iCloud settings in the Capabilities pane, click CloudKit Dashboard.

    Alternatively, go to https://icloud.developer.apple.com/dashboard.

  2. If necessary, enter your Apple ID credentials and click Sign In.

    All the containers for all the teams you belong to appear in the container pop-up menu in the upper-left corner of the window. The assets for the selected container (named Gallery in the screenshot) are displayed.

登錄CloudKit儀表板


1.在功能窗格中的iCloud設置,點擊CloudKit儀表板。
或者,去https://icloud.developer.apple.com/dashboard。


2.如果有必要,輸入你的Apple ID憑據,然後單擊登錄。


To sign out, choose Sign Out from the account pop-up menu (named Tom Clark in the screenshot) in the upper-right corner of the window.


Share Containers Between Apps

Optionally, configure your app to use multiple containers or share a container with other apps. For example, you might use one app internally to create record types and records programmatically to return a database to a known state. This app needs to share the same container as the end-user app you are developing and testing. To do this, you enable the first app to use the default container of the second app or create a custom container that both apps share. iOS and Mac apps can also be configured to share the same containers.

在應用程序之間分享容器

這功能是可選的,配置您的應用程序使用多個容器或與其他應用程序共享相同的容器。例如,你可以使用一個應用程序內部創造的記錄類型和記錄程序到數據庫恢復到已知狀態。作爲正在開發和測試的最終用戶的應用程序,這個應用程序需要共享同一個容器。要做到這一點,你啓用了第一個應用程序來使用第二個應用程序的默認容器或創建一個這兩個應用程序共享的自定義的容器。 iOS和Mac應用程序也可以被配置爲共享相同的容器。

Add Containers to an App

Select an existing container ID used by another app or create a new one. 

To add a container to an app

  1. In the Capabilities pane under the iCloud settings, select “Specify custom containers.”

    When you previously selected the CloudKit service, Xcode created a default container ID for your app that matches the bundle ID. A checkmark appears next to the default container ID.

給一個應用添加容器 

1.在該功能下的iCloud設置面板中,選擇“指定自定義容器。”
如果您之前選擇的CloudKit服務,Xcode中創建一個與應用程序包ID相匹配的默認的容器ID。複選標記旁邊出現默認容器ID。


  1. If necessary, click the Refresh button below the Containers table to download containers from MemberCenter that are used by other apps.

  2. In the row of the container ID you want to add, select the checkbox.
    Xcode updates the list of container IDs in the entitlements file.
    The screenshot below shows the Curator and Gallery app sharing the Gallery app’s default container. 

2.如果需要,點擊容器表中的刷新按鈕來下載其他應用所使用的會員中心的容器。
3.在您想要添加的容器ID的行前面,選擇複選框。

Xcode會在權利文件中更新容器ID列表。

下面的截圖展示了設置Curator和Gallery兩個應用程序共享Gallery應用的默認容器。



Create Custom Containers

Alternatively, create a custom container shared by multiple apps

Important: Only team admins can create containers. If you are an individual, you are the team agent (with admin privileges) for your one person team.

To create a custom container

  1. If "Use default container” is selected, select “Specify custom containers.”

  2. Click the Add button (+) at the bottom of the table.

  3. In the dialog that appears, enter an identifier for the container you want to add.

Warning: You can’t delete a container ID, so choose the container ID carefully.

A container ID begins with iCloud. followed by a string in reverse DNS notation, as in the iCloud.com.example.ajohnson.SharedGallery container ID.

4.Click OK.

Xcode adds the new container ID to the Xcode project entitlements file and to Member Center.


If you want to share the new container ID with another app, add the container to the app, as described in Add Containers to an App.

創建一個自定義容器(例外,創建一個多個應用共享的自定義容器)

1.如果"Use default container"被選擇了,那選擇"指定自定義容器"

2.點擊表格底部的添加按鈕(+)。

3.在出現的對話框中,輸入一個你想要添加的容器標識符。

警告:你不能刪除容器ID,所以小心設置容器標識符

容器ID一般以   iCloud. 開頭 ,後面跟着一個反向DNS表示的字符串,例如iCloud.com.example.ajohnson.SharedGallery


4.點擊OK


Verify Your Steps

You can view all the container IDs for your team in the iCloud settings or Member Center. In Member Center, you can also add containers and edit the name of containers.

To view container IDs in Member Center

  1. In Member Center, select Certificates, Identifiers & Profiles.

  2. Under Identifiers, select iCloud Containers.

驗證你的步驟

在iCloud中的設置或會員中心中您可以查看所有的容器標識。在會員中心,你還可以添加容器和容器編輯的名字。


1.在會員中心,選擇證書,標識和簡介。
2.在標識符,選擇iCloud容器。



Create an iCloud Account for Development

You’ll need an iCloud account to save records to a CloudKit container. You’ll enter the credentials for this iCloud account on the device that you run your app. If you don’t have an iCloud account, create one that you can use during development. On your Mac, launch System Preferences and click iCloud. Click Create Apple ID under the Apple ID text field and follow the instructions.


Recap

In this chapter, you learned how to:

  • Enable CloudKit in your Xcode project, which creates your app’s default container. 

  • Access CloudKit Dashboard to view the container’s schema and records.

  • Create an iCloud account to use for development.

概括


在本章中,我們學習瞭如何:


在您的Xcode項目,創造你的應用程序的默認容器啓用CloudKit。
訪問CloudKit儀表板,以查看容器的模式和記錄。
創建一個帳戶的iCloud用於發展。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章