iCloud1_Getting Started
開始Getting Started
這一章創(chuàng)建一個iOS應(yīng)用,你需要用4.2及以后版本的Xcode和iOS SDK。Xcode是蘋果為iOS和Mac OS X開發(fā)集成的開發(fā)環(huán)境。iOS SDK包括iOS平臺的編程接口。To create the iOS app in this tutorial, you need Xcode 4.2 or later and the iOS SDK. Xcode is Apple’s integrated development environment for both iOS and Mac OS X development. The iOS SDK includes the programming interfaces of the iOS platform.
如果你沒有在你的Mac上安裝Xcode,訪問?iOS Dev Center?,下載Xcode 4.2開發(fā)工具集(包含iOS 5 SDK)。雙擊下載包,根據(jù)提示一步步安裝。If you do not have Xcode installed on your Mac, visit the?iOS Dev Center?and download the Xcode 4.2 developer toolset (which includes the iOS 5 SDK). Double-click the package and follow the installer instructions.
重點Important:?你需要一個可以運行iOS 5的設(shè)備,并配置一個云賬號,這樣才可以完成指導(dǎo)的步驟。文檔注定iCloud必須來自一個設(shè)備,而不是從iOS模擬器。You will need a device running iOS 5 and configured with an active iCloud account in order to complete this tutorial. Documents destined for iCloud must originate from a device and not from iOS Simulator.
?
創(chuàng)建一個新的項目Create a New Project
開始開發(fā)APP,創(chuàng)建一個新的Xcode項目。To get started developing your app, create a new Xcode project.
創(chuàng)建一個新項目To create a new project打開Xcode。Open Xcode.
選擇文件>新建>新建項目,來完成創(chuàng)建你的項目。Choose File > New > New Project to initiate the creation of your project.
在iOS部分,選擇應(yīng)用Application,在模板列表中選擇主從復(fù)合結(jié)構(gòu)應(yīng)用Master-Detail Application,然后點擊下一步。In the iOS section, select Application, select Master-Detail Application from the list of templates, and then click Next.
一個新的對話框會彈出,提示你輸入為你的應(yīng)用命名,并且為你的應(yīng)用選擇其他附加的選項。A new dialog appears that prompts you to name your app and choose additional options for your project.
填好應(yīng)用名、公司標(biāo)示符、類的前綴。Fill in the Product Name, Company Identifier, and Class Prefix fields.
(舉例)你可以使用如下值:You can use the following values:
-
應(yīng)用名稱Product Name:?SimpleTextEditor
-
公司標(biāo)識Company Identifier: Your company identifier, if you have one, or?edu.self?if you do not have one.
-
類的前綴Class Prefix: STE
在設(shè)備家族下拉菜單中,選擇iPhone這一項。In the Device Family pop-up menu, make sure that iPhone is selected.
在多選框中的使用Storyboard和使用自動引用計數(shù)器要勾選,單元測試選項沒有選中。(這些是默認(rèn)的設(shè)置)。Make sure that the Use Storyboard and Use Automatic Reference Counting options are selected and that the Include Unit Tests option is unselected. (These are the default values.)
點擊下一步Click Next.
彈出另一個對話框,問你是否想要保存項目到指定的地方。Another dialog appears asking you to specify where you want to save your project.
為你的項目選擇指定的位置(離開,保持源代碼控制選項沒有選中),然后點擊創(chuàng)建。Specify a location for your project (leave the Source Control option unselected) and then click Create.
你應(yīng)該可以看到一個新的項目窗口,類似于這樣:You should see a new project window similar to this:
因為你還沒有添加iCloud功能,你可以在模擬器上編譯并運行你的應(yīng)用。正如它的名字暗指的那樣,模擬器允許你取得一個想法,關(guān)于你的應(yīng)用如何顯示和動作,如果運行在一個基于iOS的設(shè)備上。總之,項目的余下部分,你應(yīng)該在一個配置了iOS 5、有一個可用的iCloud賬號的iOS設(shè)備上編譯并運行項目。Because you have not yet added any iCloud functionality, you can build your app and run it in the Simulator application that is included in Xcode. As its name implies, Simulator allows you to get an idea of how your app would look and behave if it were running on an iOS–based device. However, for the rest of the project, you should build your app and run it on an iOS device that is configured with iOS 5 and has an active iCloud account.
配置你的應(yīng)用的iCloud權(quán)利Configure Your Project’s iCloud Entitlements
應(yīng)用要用iCloud,必須配置特定的權(quán)利,確保進(jìn)入用戶賬號。你可以直接從Xcode中配置這些權(quán)利。Apps that use iCloud must be configured with special entitlements to ensure secure access to the user’s account. You configure these entitlements directly from Xcode.
配置iCloud權(quán)利To configure your iCloud entitlements為你的項目選擇目標(biāo)Select the target for your project.
在概要選項卡中,滾動到Entitlements權(quán)限部分。In the Summary tab, scroll down to the Entitlements section.
選擇可用的權(quán)限選項。Select the Enable Entitlements option.
Xcode添加一個權(quán)限文件到你的應(yīng)用,并自動進(jìn)入訪問iCloud的默認(rèn)值。Xcode adds an entitlements file to your project and automatically enters default values for accessing iCloud.
為這一章,由Xcode提供的默認(rèn)權(quán)限值是足夠的。在你自己的項目中,可以在需要時改變這些值來匹配你的應(yīng)用的包標(biāo)示符的另一個值。例如,如果你為應(yīng)用創(chuàng)建一個自由版本,你可以為付費版本分配包標(biāo)示符,這樣兩個版本的應(yīng)用就可以公用數(shù)據(jù)。這樣做意味著,將自由版本升級到付費版不會使得用戶先前的數(shù)據(jù)很遙遠(yuǎn)。For this tutorial, the default entitlement values provided by Xcode are sufficient. In your own projects, you can change these values if needed to match the bundle identifier for another one of your app’s. For example, if you create a free version of your app, you can assign the bundle identifier for the paid version so that the two versions of the app share data. Doing so means that upgrading from the free version to the paid one does not make the user’s previous data inaccessible.
注意Note:?雖然這一節(jié)只使用到了iCloud容器相關(guān)的權(quán)利,但是對于一個在iCloud鍵值存儲領(lǐng)域是沒有害處的。在你傳輸?shù)膽?yīng)用中,不應(yīng)該包含應(yīng)用程序沒有用到的權(quán)限對應(yīng)的值。Although this tutorial uses only the entitlement associated with the iCloud Containers field, there is no harm in having a value in the iCloud Key-Value Store field. In your shipping apps, though, you should not include values for entitlements that your app does not use.
?
在iOS用戶中心配置你的應(yīng)用IDConfigure Your App ID in the iOS Member Center
在你安裝iCloud應(yīng)用到一個設(shè)備上之前,必須創(chuàng)建一個應(yīng)用ID和供應(yīng)配置文件。創(chuàng)建一個應(yīng)用ID組和多個供應(yīng)配置文件,只有管理權(quán)限的用戶可以做。如果你沒有管理權(quán)限,必須讓你團(tuán)隊的其他成員來幫忙。Before you can install an iCloud app on a device, you must create an app ID and provisioning profile. Creating app IDs and provisioning profiles can only be done by administrative users. If you do not have administrative privileges, you must ask another member of your team to help you.
創(chuàng)建一個應(yīng)用IDCreating an App ID
應(yīng)用ID可以在一臺設(shè)備和iCloud上唯一標(biāo)識你的應(yīng)用。更多詳細(xì)說明,查看“Creating App IDs”?(在App Distribution Guide)使用如下細(xì)節(jié):The app ID uniquely identifies your app on a device and in iCloud. For detailed instructions, see?“Creating App IDs”?inApp Distribution Guide. Use the following details:
-
描述Description:?Simple Text Editor
-
應(yīng)用服務(wù)App Services: Enable iCloud
-
應(yīng)用ID后綴App ID Suffix: Explicit app identifier
-
包標(biāo)示符Bundle Identifier: 使用你的應(yīng)用的包標(biāo)示符。標(biāo)識符是由你的公司標(biāo)識和項目名結(jié)合組成的。查看在Xcode中的這個值,到概要面板中的應(yīng)用目標(biāo)的標(biāo)示符區(qū)域查看。Use your app’s bundle identifier. This is a combination of your company identifier and the SimpleTextEditor app name. To see this value in Xcode, go to the Summary pane of your app target and look in the Identifier field.
生成一個配置概要文件Generating a Provisioning Profile
你需要生成一個配置概要文件,可以在開發(fā)中使用。詳細(xì)說明,查看“Creating Development Provisioning Profiles”(在?App Distribution Guide)。使用如下細(xì)節(jié):You also need to generate a provisioning profile that you can use during development. For detailed instructions, see“Creating Development Provisioning Profiles”?in?App Distribution Guide. Use the following details:
-
配置文件名Profile Name:?My Simple Text Editor Profile
-
證書Certificates: Select your user name.
-
應(yīng)用IDApp ID:?Simple Text Editor?(This is the app ID you configured previously.)
-
設(shè)備Devices: Select the devices you plan to use to test the app.
如果你的機(jī)器配置有適當(dāng)?shù)淖C書,配置概要文件出現(xiàn)在Xcode組織者時應(yīng)該在有效的。如果有任何在安裝證書中不匹配的,Xcode顯示一個對應(yīng)的消息到組織者窗口。你可以用這個信息來幫助診斷出問題。更多關(guān)于診斷配置概要文件問題,查看?“Diagnosing Provisioning Profile Issues”?If your machine is configured with the appropriate certificates, the provisioning profile should show up in the Xcode organizer as valid. If there is any mismatch in the installed certificates, Xcode displays an appropriate message in the Organizer window. You can use this information to help diagnose the problem. For more information about diagnosing provisioning profile issues, see?“Diagnosing Provisioning Profile Issues.”
用客戶配置概要文件修改你的項目Update Your Project to Use the Custom Provisioning Profile
生成一個客戶配置概要文件后,你必須將該配置文件關(guān)聯(lián)到你的項目中。After generating the custom provisioning profile for your app, you must associate that profile with your project.
關(guān)聯(lián)項目和配置概要文件To associate the provisioning profile with your project為你的項目選擇目標(biāo)Select the target for your project.
在編譯設(shè)置選項卡中,尋找代碼簽名身份In the Build Settings tab, search for Code Signing Identity.
在彈出的代碼簽名身份中,選擇你的配置概要文件。From the Code Signing Identity popup, select your provisioning profile.
你必須指定你為應(yīng)用創(chuàng)建的特定的配置概要文件。不可以用通用配置概要文件類測試iCloud應(yīng)用。You must specify the provisioning profile you created specifically for your app. You cannot use the generic Team Provisioning Profile to test iCloud apps.
初始化應(yīng)用程序的iCloud容器Initialize Your App’s iCloud Container
在你第一次嘗試使用iCloud,需要調(diào)用URLForUbiquityContainerIdentifier方法,給系統(tǒng)一個機(jī)會,準(zhǔn)備為你的應(yīng)用使用iCloud。第一次調(diào)用這個方法,修改你的應(yīng)用沙盒,這樣可以通過它的容器目錄。它還執(zhí)行其他檢查,以確保iCloud和配置當(dāng)前設(shè)備是實際可用的。因為這些檢查需要些時間,你應(yīng)該在應(yīng)用循環(huán)加載時就調(diào)用,這樣以來,在你的應(yīng)用需要進(jìn)入任何文件時,就有時間完成iCloud相關(guān)配置操作。如果你的應(yīng)用有進(jìn)入多容器目錄,你必須分開調(diào)用每一個方法。Before you attempt to use iCloud for the first time, you need to call the?URLForUbiquityContainerIdentifier:method and give the system a chance to prepare your app for iCloud use. The first time you call this method, it modifies your app sandbox so that it can access its container directories. It also performs other checks to see if iCloud is actually available and configured on the current device. Because these checks can take some time, you should call it early in your app’s launch cycle so that it has time to complete before your app needs access to any files. If your app has access to multiple container directories, you must call the method separately for each one.
初始化應(yīng)用的iCloud容器To initialize your app’s iCloud container在醒目導(dǎo)航中,選擇STEAppDeleaget.m方法In the project navigator, select?STEAppDelegate.m.
定義一個新的方法,調(diào)用initializeiCloudAccess來檢查iCloud是否可用。Define a new method called?initializeiCloudAccess?to check for iCloud availability.
一個簡單文本編輯器不能改變它的配置基于是否iCloud是可用的,這樣,這個方法只是打印結(jié)果。在你自己的應(yīng)用中,你可能會用結(jié)果來表現(xiàn)附加的配置步驟。The Simple Text Editor does not change its configuration based on whether iCloud is available, so this method just logs the results. In your own apps, you might use the result to perform additional configuration steps.
| - (void)initializeiCloudAccess { |
| dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ |
| if ([[NSFileManager defaultManager] |
| URLForUbiquityContainerIdentifier:nil] != nil) |
| NSLog(@"iCloud is available\n"); |
| else |
| NSLog(@"This tutorial requires iCloud, but it is not available.\n"); |
| }); |
| } |
在application:didFinishLaunchingWithOptions:方法,調(diào)用了initializeiCloudAccess方法。In the?application:didFinishLaunchingWithOptions:?method, call the?initializeiCloudAccessmethod.
| - (BOOL)application:(UIApplication *)application |
| didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { |
| [self initializeiCloudAccess]; |
| ? |
| // Override point for customization after application launch. |
| return YES; |
| } |
你自己的應(yīng)用可以用這個早調(diào)用URLForUbiquityContainerIdentifier:方法來表現(xiàn)一些應(yīng)用-特定的任務(wù),關(guān)聯(lián)到可用的iCloud。例如,你可能會用不同的返回結(jié)果來配置你的應(yīng)用的不同的數(shù)據(jù)結(jié)構(gòu)。你可能會用它為你的用戶接口來設(shè)置配置選項。因為這個方法可能會返回它的值在你的用戶接口配置好之前或者之后。你不應(yīng)該直接從這里嘗試改變你的用戶接口。反之,設(shè)置一個標(biāo)志,并注意適當(dāng)?shù)慕涌趯ο?#xff0c;應(yīng)用配置已經(jīng)改變了。這些對象應(yīng)該可以根據(jù)標(biāo)志的值進(jìn)行適當(dāng)動作。Your own apps can use this early call of the?URLForUbiquityContainerIdentifier:?method to perform some app-specific tasks related to iCloud availability. For example, you might use the result to configure your app’s data structures differently. You might also use it to set configuration options for your user interface. Because this method might return its value either before or after your user interface is configured, you should not attempt to modify your interface directly from here. Instead, set a flag and notify the appropriate interface objects that the app configuration has changed. Those objects should then take appropriate action based on the value of the flag.
扼要重述Recap
在這一章,你用Xcode來創(chuàng)建一個新的基于主從復(fù)合結(jié)構(gòu)模板的項目。然后,配置iCloud權(quán)限到你的項目。你也可以創(chuàng)建一個應(yīng)用ID,并且使用iOS會員中心和你的項目,為你的項目供應(yīng)配置文件。最后,你的應(yīng)用程序的啟動代碼初始化你的iCloud容器目錄。In this chapter, you used Xcode to create a new project based on the Master-Detail template. Then, you configured the iCloud entitlements for your project. You also created an app ID and provisioning profile for your project using the iOS Member Center and associated the provisioning profile with your project. Finally, you initialized your iCloud container directory in your app’s launch code.
在這一點,你的項目已經(jīng)配置好,可以被安裝到你指定的iOS設(shè)備上了。下一節(jié),你將開始寫你需要的代碼,得到iCloud文件提供有力的支持。At this point, your project is configured and ready to be installed on the iOS devices you specified. In the next chapter, you will start writing the code you need to take advantage of iCloud’s document support.
轉(zhuǎn)載于:https://www.cnblogs.com/zyingn/articles/iOS_translation9_2.html
總結(jié)
以上是生活随笔為你收集整理的iCloud1_Getting Started的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大作文_p2_v1.0
- 下一篇: 学会不在意