iCloud1_Getting Started
開始Getting Started
這一章創建一個iOS應用,你需要用4.2及以后版本的Xcode和iOS SDK。Xcode是蘋果為iOS和Mac OS X開發集成的開發環境。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開發工具集(包含iOS 5 SDK)。雙擊下載包,根據提示一步步安裝。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的設備,并配置一個云賬號,這樣才可以完成指導的步驟。文檔注定iCloud必須來自一個設備,而不是從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.
?
創建一個新的項目Create a New Project
開始開發APP,創建一個新的Xcode項目。To get started developing your app, create a new Xcode project.
創建一個新項目To create a new project打開Xcode。Open Xcode.
選擇文件>新建>新建項目,來完成創建你的項目。Choose File > New > New Project to initiate the creation of your project.
在iOS部分,選擇應用Application,在模板列表中選擇主從復合結構應用Master-Detail Application,然后點擊下一步。In the iOS section, select Application, select Master-Detail Application from the list of templates, and then click Next.
一個新的對話框會彈出,提示你輸入為你的應用命名,并且為你的應用選擇其他附加的選項。A new dialog appears that prompts you to name your app and choose additional options for your project.
填好應用名、公司標示符、類的前綴。Fill in the Product Name, Company Identifier, and Class Prefix fields.
(舉例)你可以使用如下值:You can use the following values:
-
應用名稱Product Name:?SimpleTextEditor
-
公司標識Company Identifier: Your company identifier, if you have one, or?edu.self?if you do not have one.
-
類的前綴Class Prefix: STE
在設備家族下拉菜單中,選擇iPhone這一項。In the Device Family pop-up menu, make sure that iPhone is selected.
在多選框中的使用Storyboard和使用自動引用計數器要勾選,單元測試選項沒有選中。(這些是默認的設置)。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.
為你的項目選擇指定的位置(離開,保持源代碼控制選項沒有選中),然后點擊創建。Specify a location for your project (leave the Source Control option unselected) and then click Create.
你應該可以看到一個新的項目窗口,類似于這樣:You should see a new project window similar to this:
因為你還沒有添加iCloud功能,你可以在模擬器上編譯并運行你的應用。正如它的名字暗指的那樣,模擬器允許你取得一個想法,關于你的應用如何顯示和動作,如果運行在一個基于iOS的設備上。總之,項目的余下部分,你應該在一個配置了iOS 5、有一個可用的iCloud賬號的iOS設備上編譯并運行項目。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.
配置你的應用的iCloud權利Configure Your Project’s iCloud Entitlements
應用要用iCloud,必須配置特定的權利,確保進入用戶賬號。你可以直接從Xcode中配置這些權利。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權利To configure your iCloud entitlements為你的項目選擇目標Select the target for your project.
在概要選項卡中,滾動到Entitlements權限部分。In the Summary tab, scroll down to the Entitlements section.
選擇可用的權限選項。Select the Enable Entitlements option.
Xcode添加一個權限文件到你的應用,并自動進入訪問iCloud的默認值。Xcode adds an entitlements file to your project and automatically enters default values for accessing iCloud.
為這一章,由Xcode提供的默認權限值是足夠的。在你自己的項目中,可以在需要時改變這些值來匹配你的應用的包標示符的另一個值。例如,如果你為應用創建一個自由版本,你可以為付費版本分配包標示符,這樣兩個版本的應用就可以公用數據。這樣做意味著,將自由版本升級到付費版不會使得用戶先前的數據很遙遠。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:?雖然這一節只使用到了iCloud容器相關的權利,但是對于一個在iCloud鍵值存儲領域是沒有害處的。在你傳輸的應用中,不應該包含應用程序沒有用到的權限對應的值。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用戶中心配置你的應用IDConfigure Your App ID in the iOS Member Center
在你安裝iCloud應用到一個設備上之前,必須創建一個應用ID和供應配置文件。創建一個應用ID組和多個供應配置文件,只有管理權限的用戶可以做。如果你沒有管理權限,必須讓你團隊的其他成員來幫忙。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.
創建一個應用IDCreating an App ID
應用ID可以在一臺設備和iCloud上唯一標識你的應用。更多詳細說明,查看“Creating App IDs”?(在App Distribution Guide)使用如下細節: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
-
應用服務App Services: Enable iCloud
-
應用ID后綴App ID Suffix: Explicit app identifier
-
包標示符Bundle Identifier: 使用你的應用的包標示符。標識符是由你的公司標識和項目名結合組成的。查看在Xcode中的這個值,到概要面板中的應用目標的標示符區域查看。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
你需要生成一個配置概要文件,可以在開發中使用。詳細說明,查看“Creating Development Provisioning Profiles”(在?App Distribution Guide)。使用如下細節: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.
-
應用IDApp ID:?Simple Text Editor?(This is the app ID you configured previously.)
-
設備Devices: Select the devices you plan to use to test the app.
如果你的機器配置有適當的證書,配置概要文件出現在Xcode組織者時應該在有效的。如果有任何在安裝證書中不匹配的,Xcode顯示一個對應的消息到組織者窗口。你可以用這個信息來幫助診斷出問題。更多關于診斷配置概要文件問題,查看?“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
生成一個客戶配置概要文件后,你必須將該配置文件關聯到你的項目中。After generating the custom provisioning profile for your app, you must associate that profile with your project.
關聯項目和配置概要文件To associate the provisioning profile with your project為你的項目選擇目標Select the target for your project.
在編譯設置選項卡中,尋找代碼簽名身份In the Build Settings tab, search for Code Signing Identity.
在彈出的代碼簽名身份中,選擇你的配置概要文件。From the Code Signing Identity popup, select your provisioning profile.
你必須指定你為應用創建的特定的配置概要文件。不可以用通用配置概要文件類測試iCloud應用。You must specify the provisioning profile you created specifically for your app. You cannot use the generic Team Provisioning Profile to test iCloud apps.
初始化應用程序的iCloud容器Initialize Your App’s iCloud Container
在你第一次嘗試使用iCloud,需要調用URLForUbiquityContainerIdentifier方法,給系統一個機會,準備為你的應用使用iCloud。第一次調用這個方法,修改你的應用沙盒,這樣可以通過它的容器目錄。它還執行其他檢查,以確保iCloud和配置當前設備是實際可用的。因為這些檢查需要些時間,你應該在應用循環加載時就調用,這樣以來,在你的應用需要進入任何文件時,就有時間完成iCloud相關配置操作。如果你的應用有進入多容器目錄,你必須分開調用每一個方法。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.
初始化應用的iCloud容器To initialize your app’s iCloud container在醒目導航中,選擇STEAppDeleaget.m方法In the project navigator, select?STEAppDelegate.m.
定義一個新的方法,調用initializeiCloudAccess來檢查iCloud是否可用。Define a new method called?initializeiCloudAccess?to check for iCloud availability.
一個簡單文本編輯器不能改變它的配置基于是否iCloud是可用的,這樣,這個方法只是打印結果。在你自己的應用中,你可能會用結果來表現附加的配置步驟。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:方法,調用了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; |
| } |
你自己的應用可以用這個早調用URLForUbiquityContainerIdentifier:方法來表現一些應用-特定的任務,關聯到可用的iCloud。例如,你可能會用不同的返回結果來配置你的應用的不同的數據結構。你可能會用它為你的用戶接口來設置配置選項。因為這個方法可能會返回它的值在你的用戶接口配置好之前或者之后。你不應該直接從這里嘗試改變你的用戶接口。反之,設置一個標志,并注意適當的接口對象,應用配置已經改變了。這些對象應該可以根據標志的值進行適當動作。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來創建一個新的基于主從復合結構模板的項目。然后,配置iCloud權限到你的項目。你也可以創建一個應用ID,并且使用iOS會員中心和你的項目,為你的項目供應配置文件。最后,你的應用程序的啟動代碼初始化你的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.
在這一點,你的項目已經配置好,可以被安裝到你指定的iOS設備上了。下一節,你將開始寫你需要的代碼,得到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.
轉載于:https://www.cnblogs.com/zyingn/articles/iOS_translation9_2.html
總結
以上是生活随笔為你收集整理的iCloud1_Getting Started的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大作文_p2_v1.0
- 下一篇: Python 处理server返回gzi