首页 > iCloud1_Getting Started

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
  1. 打开Xcode。Open Xcode.

  2. 选择文件>新建>新建项目,来完成创建你的项目。Choose File > New > New Project to initiate the creation of your project.

  3. 在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.

  4. 填好应用名、公司标示符、类的前缀。Fill in the Product Name, Company Identifier, and Class Prefix fields.

    (举例)你可以使用如下值:You can use the following values:

    • 应用名称Product NameSimpleTextEditor

    • 公司标识Company Identifier: Your company identifier, if you have one, or edu.self if you do not have one.

    • 类的前缀Class Prefix: STE

  5. 在设备家族下拉菜单中,选择iPhone这一项。In the Device Family pop-up menu, make sure that iPhone is selected.

  6. 在多选框中的使用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.)

  7. 点击下一步Click Next.

    弹出另一个对话框,问你是否想要保存项目到指定的地方。Another dialog appears asking you to specify where you want to save your project.

  8. 为你的项目选择指定的位置(离开,保持源代码控制选项没有选中),然后点击创建。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
  1. 为你的项目选择目标Select the target for your project.

  2. 在概要选项卡中,滚动到Entitlements权限部分。In the Summary tab, scroll down to the Entitlements section.

  3. 选择可用的权限选项。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:

  • 描述DescriptionSimple 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 NameMy Simple Text Editor Profile

  • 证书Certificates: Select your user name.

  • 应用IDApp IDSimple 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
  1. 为你的项目选择目标Select the target for your project.

  2. 在编译设置选项卡中,寻找代码签名身份In the Build Settings tab, search for Code Signing Identity.

  3. 在弹出的代码签名身份中,选择你的配置概要文件。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
  1. 在醒目导航中,选择STEAppDeleaget.m方法In the project navigator, select STEAppDelegate.m.

  2. 定义一个新的方法,调用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
    ");
          else
             NSLog(@"This tutorial requires iCloud, but it is not available.
    ");
       });
    }
  3. 在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

更多相关:

  • 上篇笔记中梳理了一把 resolver 和 balancer,这里顺着前面的流程走一遍入口的 ClientConn 对象。ClientConn// ClientConn represents a virtual connection to a conceptual endpoint, to // perform RPCs. // //...

  • 我的实验是基于PSPNet模型实现二维图像的语义分割,下面的代码直接从得到的h5文件开始往下做。。。 也不知道是自己的检索能力出现了问题还是咋回事,搜遍全网都没有可以直接拿来用的语义分割代码,东拼西凑,算是搞成功了。 实验平台:Windows、VS2015、Tensorflow1.8 api、Python3.6 具体的流程为:...

  • Path Tracing 懒得翻译了,相信搞图形学的人都能看得懂,2333 Path Tracing is a rendering algorithm similar to ray tracing in which rays are cast from a virtual camera and traced through a s...

  • configure_file( [COPYONLY] [ESCAPE_QUOTES] [@ONLY][NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ]) 我遇到的是 configure_file(config/config.in ${CMAKE_SOURCE_DIR}/...

  •     直接复制以下代码创建一个名为settings.xml的文件,放到C:UsersAdministrator.m2下即可