Iphone Development Guide
Iphone Development Guide
2009-08-06
Apple Inc. 2009 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, mechanical, electronic, photocopying, recording, or otherwise, without prior written permission of Apple Inc., with the following exceptions: Any person is hereby authorized to store documentation on a single computer for personal use only and to print copies of documentation for personal use provided that the documentation contains Apples copyright notice. The Apple logo is a trademark of Apple Inc. Use of the keyboard Apple logo (Option-Shift-K) for commercial purposes without the prior written consent of Apple may constitute trademark infringement and unfair competition in violation of federal and state laws. No licenses, express or implied, are granted with respect to any of the technology described in this document. Apple retains all intellectual property rights associated with the technology described in this document. This document is intended to assist application developers to develop applications only for Apple-labeled computers. Every effort has been made to ensure that the information in this document is accurate. Apple is not responsible for typographical errors. Apple Inc. 1 Infinite Loop Cupertino, CA 95014 408-996-1010 App Store is a service mark of Apple Inc. Apple, the Apple logo, Carbon, Cocoa, Dashcode, iPhoto, iPod, iTunes, Keychain, Logic, Mac, Mac OS, Objective-C, Quartz, QuickTime, Safari, Shake, and Xcode are trademarks of Apple Inc., registered in the United States and other countries. Finder, Instruments, iPhone, and Spotlight are trademarks of Apple Inc. Intel and Intel Core are registered trademarks of Intel Corportation or its subsidiaries in the United States and other countries. Java and all Java-based trademarks are trademarks or registered trademarks of Sun
Microsystems, Inc. in the U.S. and other countries. OpenGL is a registered trademark of Silicon Graphics, Inc. Simultaneously published in the United States and Canada.
Even though Apple has reviewed this document, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED AS IS, AND YOU, THE READER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND ACCURACY. IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OR INACCURACY IN THIS DOCUMENT, even if advised of the possibility of such damages. THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer, agent, or employee is authorized to make any modification, extension, or addition to this warranty. Some states do not allow the exclusion or limitation of implied warranties or liability for incidental or consequential damages, so the above limitation or exclusion may not apply to you. This warranty gives you specific legal rights, and you may also have other rights which vary from state to state.
Contents
Introduction
Introduction 9
Organization of This Document 9 Installing the iPhone SDK 10 See Also 10
Chapter 1
Chapter 2
Configuring Applications 25
Editing Property-List Files 25 Managing Application Entitlements 27 Conditionalizing Compilation and Linking 29 Compiling Source Code Conditionally for iPhone Applications 29 Linking Frameworks Conditionally for iPhone Applications 30
Chapter 3
Running Applications 31
Running Sample Applications 31 Specifying the Buildtime Environment 32 Setting the Base SDK 32 Setting Your Code Signing Identity 33 Setting the Architecture 35 Setting the Active Build Configuration 35 Specifying the Runtime Environment 35 Setting the Active SDK 36 Building Your Application 38 Solving Build Errors 38
3
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CONTENTS
Running Your Application 39 Streamlining the Build-and-Run Workflow 40 Managing Application Data 40 Further Exploration 42 Chapter 4
Chapter 5
Managing Devices 47
Accessing the iPhone Developer Program Portal 47 Preparing Devices for Development 47 Setting Your Application ID 49 Registering Your Device with the Program Portal 49 Installing iPhone OS on Your Device 50 Obtaining Your Development Certificate 51 Adding Your Development Certificate to Your Keychain 51 Obtaining Your Provisioning Profile 52 Adding Your Provisioning Profile to the Xcode Organizer 52 Installing Your Provisioning Profile on Your Device 52 Restoring System Software 53 Running Applications on a Device 54 Capturing Screen Shots 54 Managing Your Digital Identities 54
Chapter 6
Debugging Applications 57
Debugging Facilities Overview 57 Viewing Console and Crash Logs 58 Finding Memory Leaks 59
Chapter 7
4
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CONTENTS
Setting Up Application Testing 64 Writing Tests 69 Running Tests 70 Running Logic Tests 70 Running Application Tests 71 Writing Testable Code 71 Chapter 8
Tuning Applications 73
The Instruments Application 73 The Shark Application 74
Chapter 9
iPhone Development FAQ 83 Hello, World! Source Code 85 Unit-Test Result Macro Reference 87
Unconditional Failure 87 STFail 87 Equality Tests 87 STAssertEqualObjects 87 STAssertEquals 88 STAssertEqualsWithAccuracy 88 Nil Tests 89 STAssertNil 89 STAssertNotNil 90 Boolean Tests 90 STAssertTrue 90 STAssertFalse 90 Exception Tests 91 STAssertThrows 91 STAssertThrowsSpecific 91 STAssertThrowsSpecificNamed 92
5
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CONTENTS
6
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
Chapter 2
Configuring Applications 25
Figure 2-1 Figure 2-2 Figure 2-3 Figure 2-4 Listing 2-1 Listing 2-2 Property-list editor window with an info-plist file 26 Adding a sibling property in the property-list editor 26 Specifying a propertys type in the property-list editor 27 Adding a child property in the property-list editor 27 Determining whether youre compiling for the simulator 29 Determining whether youre compiling for iPhone OS 30
Chapter 3
Running Applications 31
Figure 3-1 Figure 3-2 Figure 3-3 Figure 3-4 Figure 3-5 Table 3-1 Table 3-2 Code Signing Identity build setting options 34 A keychain with a developer certificate 34 Base SDK and iPhone Deployment Target build settings 36 Viewing an applications iPhone Simulatorbased local file system 41 Downloading an applications device-based local file system 42 Valid App ID/CFBundleIdentifier property pair 39 Invalid App ID/CFBundleIdentifier property pair 39
Chapter 4
Chapter 5
Managing Devices 47
Figure 5-1 Figure 5-2 Preparing computers and devices for iPhone development 48 Organizer: Copying your device identifier 50
Chapter 9
7
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
Appendix C
8
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
INTRODUCTION
Introduction
To develop iPhone applications, you use Xcode, Apples first-class integrated development environment (IDE). Xcode provides all the tools you need to design your applications user interface and write the code that brings it to life. As you develop your application, you run it on your computer, an iPhone, or an iPod touch. This document describes the iPhone application development process. It also provides information about becoming a member of the iPhone Developer Program, which is required to run applications on devices for testing. After you finish developing your iPhone application, you submit it to the App Store, the secure marketplace where iPhone OS users obtain their applications. However, you should test your application on a small set of users before publishing it to cover a wide variety of usage patterns and get feedback about your product. This document describes how to create a group of testers for your application and how to distribute it to them. To take advantage of this document, you should be familiar with the iPhone application architecture, described in iPhone Application Programming Guide. You should also be familiar with basic programming concepts. After reading this document, youll have a basic understanding of the iPhone application development process. To enhance that knowledge, you should read the documents listed later in this introduction. Software requirements: This document applies to iPhone SDK 3.1 on Mac OS X 10.5. If youre interested in developing iPhone web applications, visit http://developer.apple.com/safari/library.
"iPhone Development Quick Start" (page 11) provides an overview of the major development tasks you follow to design, build, and run an application using Xcode. "Configuring Applications" (page 25) describes how to configure your applications properties and entitlements, and how to adapt it so that it builds correctly in the iPhone simulator and device environments. "Running Applications" (page 31) describes each of the steps required to run or debug your iPhone applications. "Using iPhone Simulator" (page 43) describes the ways in which you use your computers input devices to simulate the interaction between iPhone users and their devices.
INTRODUCTION
Introduction
"Managing Devices" (page 47) shows how to configure your computer and your device for development; how to use the Xcode Organizer to view console logs or crash information, and take screen shots of applications running on your device; and how to safeguard the digital identifications required to install applications in development on devices. "Debugging Applications" (page 57) describes the Xcode debugging facilities. "Unit Testing Applications" (page 61) introduces unit testing and describes how you can take advantage of it in your projects. "Tuning Applications" (page 73) describes Instruments and Shark, the tools you use to measure and tune your applications performance. "Publishing Applications for Testing" (page 75) describes the steps you need to perform to add testers to your team and shows how to view their crash logs. It also contains testing instructions for your testers. "iPhone Development FAQ" (page 83) lists common questions developers ask about iPhone Simulator. "Hello, World! Source Code" (page 85) contains the source code for the Hello, World! application described in "Tutorial: Hello, World!" (page 17). "Unit-Test Result Macro Reference" (page 87) describes the test-result macros you can use in your unit-test methods. "iPhone Simulator Frameworks and Libraries" (page 97) provides information about the frameworks and system libraries in the iPhone Simulator SDK
See Also
These documents describe the essential concepts you need to know about developing iPhone applications:
iPhone OS Technology Overview introduces iPhone OS and its technologies. iPhone Application Programming Guide describes the architecture of an iPhone application and shows the key customization points in UIKit and other key system frameworks. Cocoa Fundamentals Guide introduces the basic concepts, terminology, architectures, and design patterns of the Cocoa frameworks and development environment. The Objective-C 2.0 Programming Language introduces object-oriented programming and describes the main programming language used for iPhone development. Dashcode User Guide, which describes how to create webpages optimized for Safari on iPhone. These web applications make use of web technologies such as HTML, CSS, and JavaScript.
10
CHAPTER 1
Developing iPhone applications is a pleasant and rewarding endeavor. To convert your ideas into products you use Xcode, the integrated development environment (IDE) used to develop iPhone applications. With Xcode you organize and edit your source files, view documentation, build your application, debug your code, and optimize your applications performance. Note: To develop iPhone applications, you must an Apple Developer Connection member. To run applications on a device, you must be member of the iPhone Developer Program. For more information, see "Managing Devices" (page 47). This chapter provides an overview of the major development tasks you follow to design, build, and run an application using Xcode. It also includes a quick tutorial that shows how to develop the ubiquitous Hello, World! application for iPhone OS.
11
CHAPTER 1
The rest of this section gives more details about these steps.
Navigation-Based Application. An application that presents data hierarchically, using multiple screens. The Contacts application is an example of a navigation-based application. OpenGL ES Application. An application that uses an OpenGL ESbased view to present images or animation. Tab Bar Application. An application that presents a radio interface that lets the user choose from several screens. The Clock application is an example of a tab bar application. Utility Application. An application that implements a main view and lets the user access a flipside view to perform simple customizations. The Stocks application is an example of a utility application. View-Based Application. An application that uses a single view to implement its user interface. Window-Based Application. This template serves as a starting point for any application, containing an application delegate and a window. Use this template when you want to implement your own view hierarchy.
If you need to develop a static library for use in an iPhone application, you can add a static library target to your project by choosing Project > New Target and selecting the Static Library target template in the iPhone OS/Cocoa Touch list. Static libraries used in iPhone applications do not need to be code signed. Therefore, you should remove the Code Signing Identity build setting definition from the static library targets you create. To do so: 1. 2. 3. Open the static-library targets Info window and display the Build pane. In the Code Signing group, select the Any iPhone OS Device conditional definition for the Code Signing Identity build setting. Change the conditional definitions value from iPhone Developer to Dont Code Sign.
To learn more about the iPhone application architecture, see iPhone Application Programming Guide. To develop an iPhone application, you work on an Xcode project. And you do most of your work on projects through the project window, which displays and organizes your source files and other resources needed to build your application. This window allows you to access and edit all the pieces of your project. Figure 1-1 shows the project window.
12
CHAPTER 1
Figure 1-1
Project window
Status bar
Detail view
The project window contains the following key areas for navigating your project:
Groups & Files list. Provides an outline view of your project contents. You can move files and folders around and organize your project contents in this list. The current selection in the Groups & Files list controls the contents displayed in the detail view. Detail view. Shows the item or items selected in the Groups & Files list. You can browse your projects contents in the detail view, search them using the search field, or sort them according to column. The detail view helps you rapidly find and access your projects contents. Toolbar. Provides quick access to the most common Xcode commands. Favorites bar. Lets you store and quickly return to commonly accessed locations in your project. The favorites bar is not displayed by default. To display the favorites bar, choose View > Layout > Show Favorites Bar. Status bar. Displays status messages for the project. During an operationsuch as building or indexingXcode displays a progress indicator in the status bar to show the progress of the current task.
Editing Code
The main tool you use to write your code is the Xcode text editor. This advanced text editor provides several convenient features:
Header-file lookup. By Commanddouble-clicking a symbol, you can view the header file that declares the symbol.
13
CHAPTER 1
API reference lookup. By Optiondouble-clicking a symbol, you get access to API reference that provides information about the symbols usage. Code completion. As you type code, you can have the editor help out by inserting text for you that completes the name of the symbol Xcode thinks youre going to enter. Xcode does this in an unobtrusive and overridable manner. Code folding. With code folding, you can collapse code that youre not working on and display only the code that requires your attention.
For details about these and other text editor features, see The Text Editor.
As you type the name of a symbol, Xcode recognizes that symbol and offers a suggestion, as shown in Figure 1-2. You can accept suggestions by pressing Tab or Return. You may also display a list of completions by pressing Escape. Figure 1-2 Using code completion
To learn more about code completion, see Completing Code in Xcode Workspace Guide.
14
CHAPTER 1
Accessing Documentation
During development, you may need fast access to reference for a particular symbol or high-level documentation about API usage or an iPhone OS technology. Xcode gives you easy access to such resources through the Research Assistant and the Documentation window. The Research Assistant is a lightweight window, shown in Figure 1-4 (page 16), that provides a condensed view of the API reference for the selected item, without taking your focus away from the editor in which the item is located. This window provides an unobtrusive way to consult API reference. However, when you need to dig deeper into the reference, the Documentation window is just a click away. The Documentation window (Figure 1-3) lets you browse and search the developer documentation (which includes API reference, guides, and articles about particular tools or technologies) installed on your computer. It provides access to a wider and more detailed view of the documentation than the Research Assistant, for the times when you need additional help. Figure 1-3 Viewing API reference in the Documentation window
To display the API reference for a symbol in a source file, you select the symbol in the text editor and choose Help > Find Selected Text in API Reference (you can also Optiondouble-click the symbol name). This command searches for the selected symbol in the API reference for your projects SDK and displays it in the Documentation window. For example, if you select the UIFont class name in a source file and execute the Find Selected Text in API Reference command, Xcode opens the Documentation window and displays the API reference for the UIFont class.
15
CHAPTER 1
While the Documentation window is a great tool to browse the iPhone documentation library, sometimes you may not want to take your focus away from the text editor while you write code, but need basic information about a symbol in a condensed way. The Research Assistant provides such information in a small and unobtrusive window. The Research Assistant actively follows you as you move the cursor around a source file. When it recognizes a symbol for which it finds API reference, the Research Assistant displays that reference, as shown in Figure 1-4. All you have to do is glance at the Research Assistant to get essential details about the symbol. To display the Research Assistant, choose Help > Show Research Assistant. Figure 1-4 Viewing API reference in the Research Assistant
From the Research Assistant you can quickly jump to more comprehensive reference for the symbol, or even view the header that declares it. For more information about accessing documentation in Xcode, see Documentation Access.
16
CHAPTER 1
To compile and debug your code, Xcode relies on open-source tools, such as GCC and GDB. Xcode also supports team-based development with source control systems, such as Subversion, CVS, and Perforce. Building your application involves the following steps:
Compiling your source files and generating your application binary. Placing the binary in iPhone Simulator or on your device.
Xcode performs these tasks for you when you execute the Build command. See "Running Applications" (page 31) for details.
Further Exploration
To learn more about the Xcode development process, see Xcode Project Management Guide.
17
CHAPTER 1
<Xcode> represents the directory in which you installed the Xcode toolset. See Xcode Installation
Details for more information. 2. 3. Choose File > New Project. Select the Window-Based Application template and click Choose.
4. 5.
Name the project HelloWorld and choose a location for it in your file system. Add the MyView class to the project. a. Choose File > New File.
18
CHAPTER 1
b.
Select the Cocoa Touch UIView subclass template and click Next.
c. d. 6.
In the File Name text field, enter MyView.m. Select the Also create "MyView.h" option and click Finish.
Choose the active SDK for your project. If you have a development device plugged in at the time you create the project, Xcode sets the active SDK to build for your device. Otherwise, it sets it to build for iPhone Simulator.
19
CHAPTER 1
Note: To use the iPhone Device SDK you must be a member of the iPhone Developer Program. For more information, see "Accessing the iPhone Developer Program Portal" (page 47). To set the active SDK, chose an item from the Project > Set Active SDK submenu or the Overview toolbar menu in the project window.
b.
Add the following code lines to the applicationDidFinishLaunching: method, below the override-point comment.
MyView *view = [[MyView alloc] initWithFrame:[window frame]]; [window addSubview:view];
20
CHAPTER 1
[view release];
After making these changes, the code in the HelloWorldAppDelegate.m file should look like this:
#import "HelloWorldAppDelegate.h" #import "MyView.h" @implementation HelloWorldAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after app launch MyView *view = [[MyView alloc] initWithFrame:[window frame]]; [window addSubview:view]; [view release]; [window makeKeyAndVisible]; } - (void)dealloc { [window release]; [super dealloc]; } @end
Listing 1-1 shows the code that draws Hello, World! in the window. Add the highlighted code lines to the drawRect: method in the MyView.m file. Listing 1-1 Method to draw Hello, World! in a view
- (void) drawRect:(CGRect) rect { NSString *hello = @"Hello, World!"; CGPoint location = CGPointMake(10, 20); UIFont *font = [UIFont systemFontOfSize:24]; [[UIColor whiteColor] set]; [hello drawAtPoint:location withFont:font]; }
If you turned on code completion (as described in "Using Code Completion" (page 14)), as you type symbol names the text editor suggests completions for the symbol names it recognizes. For example, as you type CGPointM, the text editor suggests the completion shown in Figure 1-2 (page 14). You can take advantage of completion here by accepting the suggested completion and jumping to the parameter placeholders: 1. Jump to the first parameter by choosing Edit > Select Next Placeholder, and type 10. The Select Next Placeholder command moves you among the arguments in function or method calls that the text editor suggests as completions to the text youre typing. 2. 3. Jump to the second parameter and type 20. Enter the semicolon (;) at the end of the line and press Return.
21
CHAPTER 1
to the HelloWorldAppDelegate.m file. To learn about other possible build errors, see "Solving Build Errors" (page 38).
22
CHAPTER 1
Further Exploration
Now that you learned how to write the standard Hello, World! application for iPhone OS, you can experiment with HelloWorld, the Cocoa Touch version of this ubiquitous application. For a step-by-step tutorial in developing a more complex application, see Your First iPhone Application.
23
CHAPTER 1
24
CHAPTER 2
Configuring Applications
This chapter describes how to set up your applications properties to customize its runtime environment, configure its entitlements to take advantage of iPhone OS security features, and how to adapt it so that it builds correctly in the iPhone simulator and device environments.
Information-property list. These files, commonly referred to as info-plist files, contain essential information used by your application and iPhone OS. See The Information Property List in iPhone Application Programming Guide for information about the application properties defined in info-plist files. Entitlements. These files define properties that provide your application access to iPhone OS features (such as push notifications) and secure data (such as the users keychain).
To learn more about property-list files, see Property List Programming Guide. To edit a property-list file, perform one of these actions:
To edit it in the editor pane of the Project window, select the file in the Groups & Files list or in the detail view. To edit it in a dedicated editor window, double-click the file in the Groups & Files list or in the detail view.
For more information about the Groups & Files list, see Project Window Components in Xcode Workspace Guide. Figure 2-1 shows a property-list editor window with an info-plist file.
25
CHAPTER 2
Configuring Applications
Figure 2-1
Each row in the file specifies a property definition (or key/value pair). Key cells specify property names (and their data types). Value cells specify property values. These are the property-list editing actions you can perform with the property-list editor:
Add a sibling property. With a row selected and its disclosure triangle closed, click the Add Sibling button (shown in Figure 2-2) or press Return to add a sibling to the property.
Figure 2-2
After adding the sibling, choose the property type from the property-type menu in the key cell, as shown in Figure 2-3.
26
CHAPTER 2
Configuring Applications
Figure 2-3
Add a child property. With a row with a multi-value propertya property whose value is a list of valuesselected and its disclosure triangle open, click the Add Child button (shown in Figure 2-4) or press Return to add a child to the property.
Figure 2-4
Delete property. With a row selected, press Delete to delete the row.
To make editing property-list files convenient and to ensure the files structure is correct, the property-list editor uses property-listfile schemas to display property names in the Key column, and formatted values (such as check boxes for Boolean values) in the Value column. However, you may want to see the properties key names and values in their XML (or raw) form. To toggle between viewing the formatted keys and values and their raw form, toggle the Show Raw Keys/Values option of the property-list editor shortcut menu.
27
CHAPTER 2
Configuring Applications
To add an entitlements property-list file to your project: 1. 2. 3. 4. In the Groups & Files list, select the Resources group. Choose File > New File. Choose the iPhone OS > Code Signing > Entitlements template. Name the file Entitlements.plist. (You can use any name; just ensure it matches the value of the Code Signing Entitlements build setting, as explained later in this section.) Set the type of the property-list file to iPhone Entitlements. With the file selected in the text editor, choose View > Property List Type > iPhone Entitlements plist.
5.
6.
Add the necessary entitlement entries to the file. For each entitlement property you need to define: a. b. Click the Add Child or Add Sibling buttons to the right of the selected row. The Add Child button has three lines depicting a hierarchy, the Add Sibling button has a plus (+) sign on it. Choose the entitlement property from the pop-up menu that appears. If the entitlement you need to add doesnt appear in the menu, choose View > Property List Type > Default for File Type. Then enter the entitlement-key name and type. c. Enter the value for the property.
28
CHAPTER 2
Configuring Applications
7.
Set the Code Signing Entitlements build setting for the target to the name of the newly added entitlements property-list file.
// Set hello to "Hello, <device or simulator>"! #if TARGET_IPHONE_SIMULATOR NSString *hello = @"Hello, iPhone Simulator!"; #else NSString *hello = @"Hello, iPhone device!"; #endif
29
CHAPTER 2
Configuring Applications
Listing 2-2 shows how to use the TARGET_OS_IPHONE macro in a source to be shared between Mac OS X and iPhone OS. Listing 2-2 Determining whether youre compiling for iPhone OS
The TARGET_OS_IPHONE and TARGET_IPHONE_SIMULATOR macros are defined in the TargetConditionals.h header file.
30
CHAPTER 3
Running Applications
When youre ready to run or debug your application, you build it using the Xcode build system. If there are no build errors, you can run it in iPhone Simulator or on a device. The iPhone SDK comprises two SDK families: The iPhone Simulator SDK and the iPhone Device SDK.
iPhone Simulator SDK: These SDKs build applications that run in iPhone Simulator. iPhone Device SDK: These SDKs build applications that run in a device.
These are steps you follow to build and run applications: 1. 2. 3. 4. 5. Set the applications target iPhone OS release. Set the active SDK. Set the active build configuration. Build the application. Run the application.
This chapter describes each of the steps required to run or debug your application. Start with "Running Sample Applications" (page 31) if youre interested in seeing applications that showcase iPhone OS features.
2. 3. 4.
31
CHAPTER 3
Running Applications
5.
Double-click the project package, a file with the .xcodeproj suffix. For example, HelloWorld.xcodeproj. This action opens the project in Xcode. Troubleshooting: Xcode doesnt launch: If Xcode doesnt launch, you need to download it and install it on your computer. To download Xcode, visit iPhone Dev Center.
With the sample-code project open in Xcode, follow the instructions in the following sections to build and run the application.
32
CHAPTER 3
Running Applications
33
CHAPTER 3
Running Applications
Figure 3-1
Figure 3-2
These are the possible values for the Code Signing Identity build setting:
Dont Code Sign. Choose this option if you dont want to sign your binary. Note that with this value, when you build your applications using the iPhone Device SDK the build fails. Automatic Profile Selectors. These choices look for an identity whose name starts with iPhone Developer or iPhone Distribution. A code signing identity. A specific code signing identity. The code signing identities in your default keychain are listed under the name of the provisioning profile under which you downloaded them from the iPhone Developer Program Portal. Expired or otherwise invalid identities are dimmed and cannot be chosen.
Xcode project templates are configured to use the iPhone Developer automatic selector.
34
CHAPTER 3
Running Applications
Important: If need to use different code signing identities with the same name, you must use a separate Mac OS X user account for each identity.
Standard. Produces an application binary with a common architecture, compatible with all supported iPhone OS devices. This option generates the smallest application, but it may not be optimized to run at the best possible speed for all devices. Optimized. Produces an application binary optimized for each supported iPhone OS device. However, the build time is longer than when using the Standard option, and the application is also larger because multiple instruction sets are bundled into it.
Choose the value for the Architecture build setting in the Build pane of the Target or Project Info window. If you need to build your application so that it contains executable code for a different set of architectures than these predefined values offer, you can choose Other from the Architecture build-setting value list and enter the desired iPhone OSdevice architecture names.
In the Set Active Build Configuration submenu in the Project menu In the Overview pop-up menu in the toolbar
To learn more about the Release and Debug configurations, see Building Products.
35
CHAPTER 3
Running Applications
Target the latest iPhone OS release. Targeting the latest release allows you to take advantage of all the features available in the latest version of iPhone OS. However, this approach may offer a smaller set of users capable of installing your application on their devices because your application cannot run on iPhone OS releases that are earlier than the target release. Target an earlier iPhone OS release. Targeting a noncurrent release lets you publish your application to a wide user base (because your application runs on the target OS release and later releases), but may limit the iPhone OS features your application can use.
You specify the earliest iPhone OS release on which you want your application to run with the iPhone OS Deployment Target build setting. By default, this build setting is set to the iPhone OS release that corresponds to the Base SDK build-setting value. For example, when you set Base SDK to iPhone Device 2.2.1 or iPhone Simulator 2.2.1, the value of the iPhone Deployment Target build setting is iPhone OS 2.2.1, as shown in Figure 3-3. Figure 3-3 Base SDK and iPhone Deployment Target build settings
To build your application using the iPhone Device 3.0 SDK but allow it to run on iPhone OS 2.2.1, set Base SDK to iPhone Device 3.0 and iPhone Deployment Target to iPhone OS 2.2.1. When you build your application, your deployment target selection is reflected in the MinimumOSVersion entry in the applications Info.plist file. When you publish your application to the App Store, the store indicates the iPhone OS release on which your application can run based on the value of this property. See SDK Compatibility Guide for more information.
36
CHAPTER 3
Running Applications
iPhone Device SDK: If the iPhone Device SDK release is earlier than the applications target iPhone OS release (for example, the active SDK is iPhone Device 2.2.1 and iPhone Deployment Target is iPhone OS 3.0), Xcode displays build warnings when it detects that your application is using a feature thats not available in the target OS release. See "Specifying the Runtime Environment" (page 35) for more information. You must also ensure that the symbols you use are available in the applications runtime environment using cross-development techniques. These techniques are describedin Mac OS X termsin SDK Compatibility Guide.
iPhone Simulator SDK: When using the iPhone Simulator SDK to test your application, the iPhone Simulator software version must be set to the iPhone OS release that corresponds to the iPhone Simulator SDK used to build the application. For example, if you build your application using iPhone Simulator SDK 2.2.1, you must set the iPhone Simulator software version to iPhone OS 2.2.1. See "Setting the Simulation-Environment iPhone OS Version" (page 43) for details. After testing your application in iPhone Simulator, you must test it on an iPhone OSbased device to measure and tune its performance. To be able to run your application on a device, you must be a member of the iPhone Developer Program; see "Preparing Devices for Development" (page 47) for details. When changing the active SDK from iPhone Simulator SDK to iPhone Device SDK, keep in mind that the former provides a runtime environment for Mac OS X. Some of the key frameworks iPhone Simulator uses are tailored for Mac OS X. Moving to the iPhone Device SDK means that instead of Mac OS Xbased frameworks and libraries, your application links against device-specific frameworks and libraries. Some of these frameworks and libraries are implemented differently or are not available for the device, such as the ApplicationServices framework.
37
CHAPTER 3
Running Applications
may encounter build errors after switching to the iPhone Device SDK. You may need to conditionalize your code so that the #import/#include statements that use SDK headers are compiled only when building for the appropriate platform.
38
CHAPTER 3
Running Applications
To solve the error, choose a valid code signing identity, as described in "Setting Your Code Signing Identity" (page 33).
Application ID Errors
Application ID build errors may be produced due to a conflict between the application ID set in your provisioning profile (obtained through the Program Portal) and the application ID specified by the CFBundleIdentifier property of your application. To avoid such errors, ensure that the application ID in the profile is set to com.<organization_name>.* and your applications CFBundleIdentifier property is set to com.<organization_name>.<application_name>. That is, if the application ID in your provisioning profile specifies a domain set, the application ID specified by the CFBundleIdentifier property of your application must not redefine the domain set, it may only reduce it. Table 3-1 and Table 3-2 identify valid and invalid pairing of these items. Table 3-1 Valid App ID/CFBundleIdentifier property pair
com.mycompany.*
CFBundleIdentifier com.mycompany.MyApp
CFBundleIdentifier com.mycompany.MyApp
To learn about the structure of iPhone application binaries, including details about the CFBundleIdentifier property, see The Application Bundle in iPhone Application Programming Guide. To lear about solving other build errors, use the techniques described in Viewing Errors and Warnings in Xcode Project Management Guide to fix them.
39
CHAPTER 3
Running Applications
Troubleshooting: If you get the Failed to start remote debugserver while trying to debug your application on your device, your device may not be running the iPhone OS release that corresponds to your iPhone SDK. For more information, see "Restoring System Software" (page 53).
40
CHAPTER 3
Running Applications
Figure 3-4
To make a copy of your applications devicebased file system to your Mac: 1. 2. 3. 4. 5. In Xcode, choose Window > Organizer. In the Organizer, select your device in the Devices list. In the Summary pane, click the disclosure triangle next to your application. Click the download button (the down-pointing arrow to the left of the Application Data package), as shown in Figure 3-5. In the dialog that appears, choose a location for the file-system copy.
41
CHAPTER 3
Running Applications
Figure 3-5
To restore your applications file system to a backup on your Mac: 1. 2. 3. In Xcode, open the Organizer. In the Finder, locate the directory containing the backup. Drag the backup to your application in the Summary pane of the Organizer.
Further Exploration
To learn more about using Xcode to build and run applications, see Xcode Project Management Guide.
42
Further Exploration
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CHAPTER 4
The iPhone simulation environment lets you build and run your iPhone application on your computer. You use the simulator environment to:
Find and fix major problems in your application during design and early testing. Learn about the Xcode development experience and the iPhone development environment before becoming a member of the iPhone Developer Program. Lay out and test your applications user interface. Measure your applications memory usage before carrying out detailed performance analysis on iPhone OSbased devices.
A major part of the iPhone simulation environment is the iPhone Simulator application. This application presents the iPhone user interface in a window on your computer. The application provides several ways of interacting with it using your keyboard and mouse to simulate taps and device rotation, among other gestures. iPhone OS supports the Objective-C runtime introduced in Mac OS X v10.5 except for access to Objective-C class metadata. This means that, if your application accesses Objective-C class metadata, it may not run on iPhone Simulator. See Objective-C 2.0 Runtime Reference for more information. The following sections describe the ways in which you use your computers input devices to simulate the interaction between users and their devices. They also show how to uninstall applications from the simulator and how to reset the contents of the simulator.
Rotate Left. Rotates the simulator to the left. Rotate Right. Rotates the simulator the right. Shake. Shakes the simulator. Home. Takes the simulator to the Home screen.
43
CHAPTER 4
Lock. Locks the simulator. Simulate Memory Warning. Sends the frontmost application low-memory warnings. For information on how to handle low-memory situations, see Observing Low-Memory Warnings in iPhone Application Programming Guide. Toggle In-Call Status Bar. Toggles the status bar between its normal state and its in-call state. The status bar is taller in its in-call state than in its normal state. This command shows you how your applications user interface looks when the user launches your application while a phone call is in progress.
Performing Gestures
Table 4-1 lists gestures you can perform on the simulator (see iPhone Human Interface Guidelines for gesture information). Table 4-1 Gesture Tap Performing gestures in iPhone Simulator Desktop action Click.
Touch and hold Hold down the mouse button. Double tap Swipe Double click. 1. Place the pointer at the start position. 2. Hold the mouse button. 3. Move the pointer in the swipe direction and release the mouse button. Flick 1. Place the pointer at the start position. 2. Hold the mouse button. 3. Move the pointer quickly in the flick direction and release the mouse button. Drag 1. Place the pointer at the start position. 2. Hold down the mouse button. 3. Move the pointer in the drag direction. Pinch 1. Hold down the Option key. 2. Move the circles that represent finger touches to the start position. 3. Hold down the mouse button and move the circles to the end position.
Installing Applications
Xcode installs applications in iPhone Simulator automatically when you build your application using the iPhone Simulator SDK. See "Running Applications" (page 31) for details.
44
Performing Gestures
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CHAPTER 4
In iPhone Simulator, you can install only applications that you build using the iPhone Simulator SDK. You cannot install applications from the App Store in the simulator.
Uninstalling Applications
To uninstall applications you have installed on the simulator use the same method used to uninstall applications from devices: 1. 2. 3. Place the pointer over the icon of the application you want to uninstall and hold down the mouse button until the icon starts to wiggle. Click the icons close button. Click the Home button to stop the icon wiggling.
Accelerometer Access
Although you can access your computers accelerometer (if it has one) through the UIKit framework, its readings differ from the accelerometer readings on a device. This discrepancy stems largely from the different positioning of the screen in relation to the rest of the hardware between computers and iPhone OSbased devices.
Uninstalling Applications
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
45
CHAPTER 4
The User domain comprises all user data iPhone OS stores including third-party application binaries, system databases (such as the Address Book and Calendar databases), application preferences, and so on. This location is also known as <iPhoneUserDomain>. iPhone Simulator stores system application preferences files in <iPhoneUserDomain>/Library/Preferences. Third-partyapplication preferences files are stored in
<iPhoneUserDomain>/Applications/<app_UUID>Library/Preferences.
Further Exploration
To learn about the frameworks available in iPhone Simulator, see "iPhone Simulator Frameworks and Libraries" (page 97).
46
Further Exploration
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CHAPTER 5
Managing Devices
With iPhone Simulator you can start developing iPhone applications without using iPhone OSbased devices. This way you can familiarize yourself with the API and development workflows used to develop applications. However, you must always test your applications on actual devices before publishing them to ensure that they run as intended and to tune them for performance on actual hardware. As a registered iPhone developer you can log in to the iPhone Dev Center, which provides access to iPhone developer documentation and lets you build iPhone applications that run in iPhone Simulator. (To become a registered iPhone developer, visit http://developer.apple.com/iphone.) Being a registered iPhone developer, however, doesnt allow you to run applications on iPhone OSbased devices. To do so you must be a member of the iPhone Developer Program. See "Accessing the iPhone Developer Program Portal" (page 47) for more information. This chapter shows how to add your development devices to the iPhone Developer Program and how to configure your computer for development. It also shows how to use the Xcode Organizer window to view your applications console logs or crash information, or to take screenshots of your application as it runs. The chapter also describes how to safeguard the digital identifications required to install applications in development in devices.
47
CHAPTER 5
Managing Devices
Certificate signing request. A certificate signing request (CSR) contains personal information used to generate your development certificate. You submit this request to the iPhone Developer Program Portal. Note: The Program Portal is visible only to members of the iPhone Developer Program. To become an iPhone Developer Program member, visit http://developer.apple.com/iphone/program.
Development certificate. A development certificate identifies an iPhone application developer. After the CSR is approved, you download your developer certificate from the portal and add it to your Keychain. When you build your iPhone application with Xcode, it looks for your development certificate in your keychain; if it finds the certificate, Xcode signs your application, otherwise, it reports a build error. If your development certificate is missing from your keychain, download it again from the Program Portal. Then, follow the instructions in "Adding Your Development Certificate to Your Keychain" (page 51).
Provisioning profile. A provisioning profile associates one or more development certificates, devices, and an iPhone application ID (a unique identifier for the iPhone applications you or your organization develop under an iPhone Developer Program contract). To be able to install iPhone applications signed with your development certificate on a device, you must install at least one provisioning profile on the device. This provisioning profile must identify you (through your development certificate) and your device (by listing its unique device identifier). If youre part of an iPhone developer team, other members of your team, with appropriately defined provisioning profiles, may run applications you build on their devices.
Figure 5-1 illustrates the relationship between these digital assets. Figure 5-1 Preparing computers and devices for iPhone development
Computer Certificate Signing Request Keychain Xcode Organizer Development Certificate (is stored on computer) Digital identity Public key Provisioning Profile (is stored on device) Development certificates Device identifiers App ID iPhone Developer Program Portal
These are the requirements your computer and your development device must meet so that you can build iPhone applications that run on your device:
48
CHAPTER 5
Managing Devices
Your computer must have your development certificate in your keychain. Your device must contain at least one provisioning profile that contains your developer certificate and identifies your device. Your development device must have iPhone OS 2.0 or later installed.
These are the steps you must follow to configure your computer and development device for iPhone development: 1. 2. 3. 4. 5. 6. 7. 8. Specify your application ID. Register your device with the Program Portal. Install iPhone OS on your device. Obtain your development certificate. Add your development certificate to your keychain. Obtain your provisioning profile. Add your provisioning profile to Xcode. Install your provisioning profile on your device.
Using an asterisk instead of an application name in the bundle identifier, as shown below, lets you share a single application ID between a set of related applications.
GFWOTNXFIY.com.mycompany.myappsuite.*
Note: Regardless of the format used by the iPhone application ID, application bundles must always include the application name in their bundle identifier. To learn more about the bundle identifier, see The Application Bundle in iPhone Application Programming Guide.
49
CHAPTER 5
Managing Devices
1. 2. 3. 4.
Launch Xcode. Choose Window > Organizer to open the Organizer window. Plug-in your device and select it in the devices list. Copy your device UDID from the Identifier text field in the Summary pane, as shown in Figure 5-2.
Figure 5-2
5.
Go to the portal to register your device or have your team admin register your device into the program. For more information about the portal, "Accessing the iPhone Developer Program Portal" (page 47).
50
CHAPTER 5
Managing Devices
The Certificate Assistant saves a CSR file to your desktop. This process creates a public/private key pair. The public key is stored in your development certificate. Your private key is stored in your keychain. You must ensure that you dont lose your private key and that only you have access to it. Therefore, its a good idea to backup your private key. Backing up your private key may also help if you need to use more than one computer to develop iPhone applications. You should also save your CSR, for future use. See "Managing Your Digital Identities" (page 54) for more information. 4. Submit the CSR to the Program Portal.
After the CSR is approved by your team admin, you can download your development certificate from the Program Portal (see "Accessing the iPhone Developer Program Portal" (page 47)). As with your private key, you should backup your development certificate in case you need to develop iPhone applications on another computer. See "Managing Your Digital Identities" (page 54) for details.
51
CHAPTER 5
Managing Devices
2.
In the Add Certificates dialog, ensure Keychain is set to login and click OK.
52
CHAPTER 5
Managing Devices
During nonseed periods, you must install iPhone OS using iTunes. 5. 6. Click Restore iPhone or Restore iPod, depending on your devices type. Use iTunes to name your device.
53
CHAPTER 5
Managing Devices
54
CHAPTER 5
Managing Devices
This section shows how to export your private key from your keychain in your development computer, store your CSR, private key, and development certificate in a protected disk image, and add these items to a second computer for iPhone development. To export your private key from your keychain: 1. 2. 3. 4. Launch Keychain Access. In the category list, select Keys. Select the private key you use for iPhone development. Choose Export from the private key shortcut menu. (To display the private key shortcut menu, Control-click the selected row.) 5. 6. Enter a password to protect the private key. Select a location for the private key and use the Personal Information Exchange (.p12) format for the file.
To generate a protected disk image containing your CSR, private key, and development certificate: 1. Place your CSR, private key, and development certificate file in a newly created directory, named iPhone Developer Identity Documents. Launch the Disk Utility application, located in /Applications/Utilities. Choose File > New > Disk Image from Folder. Choose the iPhone Developer Identity Documents directory you created earlier. Select a location for the new protected disk image. From the Encryption pop-up menu, choose 256-AES encryption . In the dialog that appears, enter a password for the disk image. You should deselect the Remember password in my keychain option. Otherwise, anybody with access to your account may open the disk image. 8. Place the protected disk image in a secure location.
2. 3. 4. 5. 6. 7.
Now, when you need to develop iPhone applications on another computer: 1. 2. 3. Copy the iPhone Developer Identity Documents.dmg disk-image file to the second computer. On the second computer, open the disk image. Import the private key into your keychain: a. b. c. Launch Keychain Access. Choose File > Import Items. Choose the private key file to import.
55
CHAPTER 5
Managing Devices
4.
Add the development certificate to your keychain. See "Adding Your Development Certificate to Your Keychain" (page 51) for details.
56
CHAPTER 6
Debugging Applications
This chapter describes the Xcode debugging facilities. Part of your debugging workflow may require to view or manipulate data your application writes in its file system. For example, you may need to edit the data the application has stored to recreate a particular condition you want to test. See "Managing Application Data" (page 40) for details about manipulating your applications data.
The text editor. The text editor allows you to debug your code right in your code. It provides most of the debugging features you need. You can:
Add and set breakpoints View your call stack per thread View the value of variables by hovering the mouse pointer over them Execute a single line of code Step in to, out of, or over function or method calls
Debugger strip
Gutter
Debugger datatip
57
CHAPTER 6
Debugging Applications
The Debugger window. When you need to perform more focused debugging, the Debugger window provides all the debugging features the text editor provides using a traditional interface. This window provides lists that allow you to see your call stack and the variables in scope at a glance.
Thread list
Text editor
Status bar
The GDB console. A GDB console window is available for text-based debugging.
Important: To debug successfully on a device, you must install on your computer the iPhone SDK corresponding to the iPhone OS release installed on the device. That is, you cannot debug an application on a device running iPhone OS 2.2.1 if you do not have the iPhone 2.2.1 SDK installed on your computer. For more information about the Xcode debugging facilities, see Xcode Debugging Guide.
58
CHAPTER 6
Debugging Applications
3.
Click Console.
You can use the search field to filter log entries. You can also save the log to a file. The Crash Logs pane in the Organizer contains information about application crashes. You may have to unplug your device and plug it in again to refresh the crash list.
To activate the NSZombieEnabled facility in your application: 1. 2. Choose Project > Edit Active Executable to open the executable Info window. Click Arguments.
59
CHAPTER 6
Debugging Applications
3. 4. 5.
Click the add (+) button in the Variables to be set in the environment section. Enter NSZombieEnabled in the Name column and YES in the Value column. Make sure that the checkmark for the NSZombieEnabled entry is selected.
For more information about configuring executable environments, see Configuring Executable Environments in Xcode Project Management Guide. iPhone 3.1 SDK introduces the Leaks instrument, which you can use in the Instruments application to easily find memory leaks. For more information, see Instruments User Guide.
60
CHAPTER 7
Unit tests help you write robust and secure code. Xcode provides an easy-to-use flexible unit-testing environment that you can use to ensure your code works as designed as it goes through changes. Software requirements: This feature is available in iPhone SDK 3.0 and later. This chapter introduces unit testing and describes how you can take advantage of it in your projects. For a case study in unit-testing adoption and usage, see: http://www.macdevcenter.com/pub/a/mac/2004/04/23/ocunit.html Xcode is already configured for unit testing. You dont need to install additional software.
Logic tests. These tests check the correct functionality of your code in a clean-room environment; that is, your code is not run inside an application. Logic tests let you put together very specific test cases to exercise your code at a very granular level (a single method in class) or as part of a workflow (several
61
CHAPTER 7
methods in one or more classes). You can use logic tests to perform stress-testing of your code to ensure that it behaves correctly in extreme situations that are unlikely in a running application. These tests help you produce robust code that works correctly when used in ways that you did not anticipate.
Application tests. These tests check the functionality of your code in a running application. You can use application tests to ensure that the connections of your user-interface controls (outlets and actions) remain in place, and that your controls and controller objects work correctly with your object model as you work on your application. Because application tests run only on a device, you can also use these tests to perform hardware testing, such as getting the location of the device.
Setting Up Testing
Logic unit tests (introduced in "Unit Testing Overview" (page 61)) allow you to perform exhaustive, highly tailored testing of your code. To perform logic tests, you build a unit-test bundle using the iPhone Simulator SDK. When you build the unit-test bundle, Xcode runs the test suites that are part of the bundle. You incorporate test suites into a test bundle by adding SenTestCase subclasses to the bundle. These classes contain test-case methods that call the API to exercise and report wether the calls produced the expected results. Xcode reports whether the tests passed or failed in text editor windows and the Build Results window. Application unit tests let you test your code within an application running on an iPhone OS device, with access to the resources available in the Cocoa Touch framework. This section describes how to set up a project for each type of unit test.
62
Setting Up Testing
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CHAPTER 7
d.
Ensure that LogicTests is the only target selected in the target list.
5.
6.
7.
Set the base SDK for the project to iPhone Simulator 3.0 or later. For more information about the Base SDK build setting, see "Setting the Base SDK" (page 32).
Setting Up Testing
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
63
CHAPTER 7
8.
Set the active target to LogicTests and choose Build > Build. If the unit-test bundle is configured correctly, the build fails and Xcode displays an error message in the text editor.
9.
Now make the test case pass by changing the highlighted lines in LogicTest.m:
#import "LogicTests.h" @implementation LogicTests - (void) testPass { STAssertTrue(TRUE, @""); } @end
At this point you have a correctly configured logicunit-test bundle. See "Writing Tests" (page 69) to learn how to add test cases to it.
2.
64
Setting Up Testing
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CHAPTER 7
3.
Make the MyAppTesting target dependent on the MyAppTests target by dragging MyAppTests to MyAppTesting.
Making the MyAppTesting target dependent on the MyAppTests target ensures that when you build MyAppTesting, MyAppTests gets built first (if you have modified MyAppTests since it was last built).
Setting Up Testing
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
65
CHAPTER 7
4.
Embed the MyAppTests bundle into the MyAppTesting bundle by dragging the MyAppTests.octest product to the MyAppTesting target Copy Bundle Resources build phase.
5. 6.
Add a group called Tests to the Groups & Files list (if it doesnt already exist), and select that group in the list. Add a unit-test class to the MyAppTests target. Each unit-test class in the bundle makes up a test suite. a. b. Choose File > New, select the iPhone OS unit-test class template, and click Next. Name the class MyAppTests (you can use any name for this class, but it should have the suffix Tests for easy identification). Select the option to create the header file.
c.
66
Setting Up Testing
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CHAPTER 7
d.
Ensure that MyAppTests is the only target selected in the target list.
7.
8.
9.
Set the Base SDK for the project to iPhone Device 3.0 or later. For more information about the Base SDK build setting, see "Setting the Base SDK" (page 32).
Setting Up Testing
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
67
CHAPTER 7
10. Set the active target to MyAppTesting and choose Build > Build and Run. Xcode builds your application, installs and launches it on your device, and runs the test suite, which fails. You can see the test results in the console. This outcome confirms that application unit testing is set up correctly.
11. Now make the test suite pass by changing the highlighted lines in MyAppTests.m:
#import "MyAppTests.h" @implementation LogicTests - (void) testAppDelegate { id app_delegate = [[UIApplication sharedApplication] delegate]; STAssertNotNil(app_delegate, @"Cannot find the application delegate."); } @end
68
Setting Up Testing
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CHAPTER 7
Now that you have a correctly configured application unit-test bundle, see "Writing Tests" (page 69) to learn how to add test cases to it.
Writing Tests
After configuring a unit-test bundle with a unit-test class (which implements a test suite), you add cases to the suite by adding test-case methods to the class. A test-case method is an instance method of a unit-test class thats named test..., with no parameters, and whose return type is void. Test-case methods call the API they test and report whether the API performed as expectedfor example, whether it returns the anticipated return or whether it raises an exception. Test-case methods use a set of macros to check for the expected conditions and report their findings. "Unit-Test Result Macro Reference" (page 87) describes these macros. For a test case to access the subject API, you may have to add the appropriate implementation files to the unit-test bundle and import the corresponding header files into your unit-test class. For an example of a project that uses unit tests, see the iPhoneUnitTests sample-code project. Note: iPhone unit-testcases are written in Objective-C. This is the structure a test-case method:
- (void) test<test_case_name> { ... // Set up, call test-case subject API. ST... // Report pass/fail to testing framework. ... // Tear down. }
Each test-case method is invoked independently. Therefore, each method must set up and tear down any auxiliary variables, structures, and objects it needs to interact with the subject API. Conveniently, you can add a pair of methods to a unit-test class that are called before and after each test-case method is invoked: setUp and tearDown. Just like test-case methods, the type of both methods is void and they take no arguments. This is an example of a setUp/tearDown method pair:
- (void) setUp { test_subject = [[MyClass new] retain]; STAssertNotNil(test_subject, @"Could not create test subject."); } - (void) tearDown { [test_subject release]; }
Writing Tests
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
69
CHAPTER 7
Note: When theres a reported failure in a setUp or tearDown call, the failure is ultimately reported in the test-case method that originated the call.
Running Tests
To ensure that changes you make to your code dont modify its correct behavior, you should run your test suites periodically, especially after making significant changes. This section shows how to run logic and application tests. It also shows how to set up an application target so that Xcode runs logic tests every time you build it.
Making the the target active and choosing Build > Build Choosing Build from the targets shortcut menu
The Build Results window shows the results of your tests. You can make Xcode run your logic tests every time you build your application. This way you dont have to remember to run those tests. Follow these steps to set up your application target so that building it runs your logic tests: 1. Drag your logic-test target into your application target. This action makes the application target depend on the logic-test target.
70
Running Tests
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CHAPTER 7
When you build the application target, Xcode builds the logic target first, reporting test failures in the process. 2. 3. 4. 5. In the LogicTests Info window, display the build pane. Choose All Configurations from the Configuration pop-up menu. Choose All Settings from the Show pop-up menu. In the Architectures group of the build-setting list, set Base SDK to iPhone Simulator 3.0, and deselect Build Active Architecture Only.
Define API requirements. You should define requirements and outcomes for each method or function that you add to your program. These requirements should include input and output ranges, exceptions thrown and the conditions under which they are raised, and the type of returned values (especially if they are objects). Specifying requirements and making sure that requirements are met in your code help you write robust, secure code.
71
CHAPTER 7
See the iPhoneUnitTests sample-code project for an example of using exceptions to identify and report incorrect API usage by a client.
Write test cases as you write code. As you write each API, write one or more test cases that ensure the APIs requirements are met. Its harder to write unit tests for existing code than for code you havent written or wrote recently. Check boundary conditions. If the parameter of a method expects values in a specific range, your tests should pass values that include the lowest and highest values of the range. For example, if an integer parameter can have values between 0 and 100, inclusive, three variants of your test may pass the values 0, 50, and 100, respectively. Use negative tests. Negative tests ensure your code responds to error conditions appropriately. Verify that your code behaves correctly when it receives invalid or unexpected input values. Also verify that it returns error codes or raises exceptions when it should. For example, if an integer parameter can accept values in the range 0 to 100, inclusive, you should create test cases that pass the values -1 and 101 to ensure that the API raises an exception or returns an error code. Write comprehensive test cases. Comprehensive tests combine different code modules to implement some of the more complex behavior of your API. While simple, isolated tests provide value, stacked tests exercise complex behaviors and tend to catch many more problems. These kinds of test mimic the behavior of your code under more realistic conditions. For example, in addition to adding objects to an array, you could create the array, add several objects to it, remove a few of them using different methods, and then ensure the set and number of remaining objects is correct. Cover your bug fixes with test cases. Whenever you fix a bug, write one or more tests cases that verify the fix.
72
CHAPTER 8
Tuning Applications
Optimizing your applications performance is an important phase of the development process, more so in iPhone OSbased devices, which, although powerful computing devices, do not have the memory or CPU power that desktop or portable computers possess. You also have to pay attention to your applications battery use, as it directly impacts your customers battery-life experience. This chapter describes Instruments and Shark, the tools you use to measure and tune your applications performance. Prerequisites: Follow the instructions in "Running Applications" (page 31) before trying the application-tuning techniques described in this chapter on your application.
Maximum of two fingers. If your applications user interface can respond to touch events involving more than two fingers, you can test that capability only on devices.
73
CHAPTER 8
Tuning Applications
Accelerometer. Although you can access your computers accelerometer (if it has one) through the UIKit framework, its readings differ from the accelerometer readings on a device. This discrepancy stems largely from the different positioning of the screen in relation to the rest of the hardware between computers and iPhone OSbased devices. OpenGL ES. OpenGL ES uses renderers on devices that are slightly different from those it uses in iPhone Simulator. For this reason, a scene on the simulator and the same scene on a device may not be identical at the pixel level. See Drawing with OpenGL ES in iPhone Application Programming Guide for details.
To measure your applications performance on a device: 1. 2. Build and run your application on the device as described in "Running Applications" (page 31). Launch Instruments. The Instruments application is located at <Xcode>/Applications. (<Xcode> refers to the installation location of the development tools.) 3. Choose a template, such as Activity Monitor, to create the trace document. A trace document contains one or more instruments that collect data about a process. 4. 5. 6. 7. From the Default Target pop-up menu in the toolbar, select the iPhone OSbased device containing the application from which you want to collect performance data. Add or remove instruments from the trace document to collect the desired data. Use the Default Target pop-up menu, to launch or attach to the target application. Click Record to start collecting data and use your application, exercising the areas you want to examine.
To learn more about measuring and analyzing application performance, see Instruments User Guide. This document provides general information about using Instruments.
74
CHAPTER 9
After testing and tuning your application yourself or with the assistance of your teammates, its always a good idea to perform wider testing with a representative sample of your applications potential users. Such testing may reveal issues that surface only with particular usage patterns. Incorporating a few nondeveloper users in your testing strategy lets you expose your application to a variety of usage styles, and, if such usage produces crashes in your application, allows you to collect the crash reports (also known as crash logs) from those users to help you resolve those execution problems. An iPhone application in development can run only on devices with provisioning profiles generated by the application developer. As iPhone Developer Program members, you and your fellow team members install these files on your devices as part of your development process. To include users that are not part of your team (also known as testers) in your testing strategy, you must add them as part of your team in the Program Portal and issue them test provisioning profiles (also known as ad-hoc provisioning profiles), which allow them to install on their devices applications that have not been published to the App Store. Figure 9-1 illustrates the process of adding users as testers and delivering your test application to them. Figure 9-1 Adding testers to your team
Tester Tester device ID Developer Tester device ID Program Portal device Tester Device
iTunes
75
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CHAPTER 9
Prerequisites: Before publishing your application for testing, review the information in "Running Applications" (page 31). To help testers obtain the information you need to add them to your testing program and to show them how to send you crash logs, you can send them the information in "Instructions for Application Testers" (page 79). Important: To add testers to your team, you must be a member of the iPhone Developer Program. See "Managing Devices" (page 47) for details. The remainder of this chapter describes the steps you need to perform to add testers to your team and shows how to import the crash logs they send you into the Organizer.
76
CHAPTER 9
Figure 9-2
The iTunes artwork your testers see should be your applications icon. This artwork must be a 512 x 512 JPEG or PNG file named iTunesArtwork. Note that the file must not have an extension. After generating the file of your applications icon, follow these steps to add it to your application: 1. 2. 3. 4. Open your project in Xcode. In the Groups & Files list, select the Resources group. Choose Project > Add to Project, navigate to your iTunesArtwork file, and click Add. In the dialog that appears, select the Copy items option and click Add.
77
CHAPTER 9
Remember to keep the binary and its corresponding dSYM file on your file system (copy them to a directory that contains a subdirectory for each build youve released to your teammates or to testers) so that theyre indexed by Spotlight. Send your application binary and the testers provisioning profile to the tester. One way of accomplishing this task is by compressing these items and emailing them to the tester: 1. 2. In the Finder, select the two files and choose File > Compress. Name the archive <application_name> for <user_name>.zip. For example, MyTestApp for Anna Haro.zip. In the Finder, select the archive and choose Finder > Services > Mail > Send File. In the body of the message make sure to include your applications target iPhone OS release. If the testers iPhone OS version is earlier than the one for which your application was built, they will not be able to install the application on their device.
3. 4.
When a tester receives the items, she or he follows the instructions in "Instructions for Application Testers" (page 79) to install the application and the provisioning profile.
78
CHAPTER 9
79
CHAPTER 9
1.
Drag the provisioning profile (the file with the .mobileprovision extension) to the iTunes Library group. Drag the application (the file with the .app extension) to the iTunes Library group. The application appears in the Applications list.
2.
3.
Sync your device. If the version of iPhone OS on your device is earlier than the test application can run on, you need to update your device with the current release of iPhone OS.
8. 9.
C:\Users\<user_name>\AppData\Roaming\Apple computer\Logs\CrashReporter/MobileDevice
80
CHAPTER 9
Listing 9-2
Open the folder named after your devices name and send the crash logs for the application youre testing in an email message using the subject-text format <application_name> crash logs from <your_name> (for example, MyTestApp crash logs from Anna Haro) to the applications developer.
81
CHAPTER 9
82
CHAPTER 10
Here are some common questions developers ask about iPhone development:
Can GCC 4.2 be used with the iPhone Simulator SDK? No.
Does the iPhone Simulator application run on network home directories? No.
Do Objective-C properties need to be backed up by instance variables or accessor methods for them to work? Yes.
Why do curl transitions appear as fade transitions in iPhone Simulator? Because Mac OS X doesnt support curl transitions.
Do static libraries need to be code-signed before being used in an iPhone application? No.
Why is my application having problems processing PNG files? The code that is trying to use your PNG files may not understand compressed PNG files. Turn off the Compress PNG Files build setting. For information about build settings, see Editing Build Settings in Xcode Project Management Guide.
Can I develop iPhone applications on Windows? No. iPhone applications can be developed only on Mac OS X.
How do I link all the Objective-C classes in a static library? Set the Other Linker Flags build setting to -ObjC. If that doesnt bring in all the classes, set it to -all_load.
When should I replace deprecated API? Update as soon as you can, considering the iPhone OS versions you want your application to run on. See SDK Compatibility Guide for details.
83
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
CHAPTER 10
84
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
APPENDIX A
This appendix contains the source code for the Hello, World! application described in "Tutorial: Hello, World!" (page 17). Listing A-1
main.m
// main.m #import <UIKit/UIKit.h> int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; }
Listing A-2
HelloWorldAppDelegate.h
// HelloWorldAppDelegate.h #import <UIKit/UIKit.h> @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; } @property (nonatomic, retain) IBOutlet UIWindow *window; @end
Listing A-3
HelloWorldAppDelegate.m
// HelloWorldAppDelegate.m #import "HelloWorldAppDelegate.h" #import "MyView.h" @implementation HelloWorldAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch MyView *view = [[MyView alloc] initWithFrame:[window frame]]; [window addSubview:view]; [view release]; [window makeKeyAndVisible]; }
85
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
APPENDIX A
Listing A-4
MyView.h
Listing A-5
MyView.m
// MyView.m #import "MyView.h" @implementation MyView - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // Initialization code } return self; } - (void)drawRect:(CGRect)rect { NSString *hello = @"Hello, World!"; CGPoint location = CGPointMake(10, 20); UIFont *font = [UIFont systemFontOfSize:24]; [[UIColor whiteColor] set]; [hello drawAtPoint:location withFont:font]; } - (void)dealloc { [super dealloc]; } @end
86
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
APPENDIX B
The SenTestingKit framework defines a set of test-case result macros that allow you to report the test-case results to the framework. When a test fails, the framework emits a test-failure message, which Xcode displays in text-editor, Build Results, or console windows, depending on the type of unit tests being performed. The following sections describe the test-result macros you can use in your test-case methods. These macros are declared in SenTestCase.h. Important: When the expressions your test cases evaluate throw exceptions, they produce unknown errors. To test whether your code raises exceptions, create test cases that explicitly check for the presence or absence or exceptions; see "Exception Tests" (page 91).
Unconditional Failure
STFail
Fails the test case.
STFail(failure_description, ...)
Parameters
failure_description
Equality Tests
STAssertEqualObjects
Fails the test case when two objects are different.
STAssertEqualObjects(object_1, object_2, failure_description, ...)
Parameters
Unconditional Failure
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
87
APPENDIX B
object_1
An object.
object_2
An object.
failure_description
(Optional) A comma-separated list of arguments to substitute into failure_description. Detail The test fails when [object_1 isEqualTo:object_2] is false.
STAssertEquals
Fails the test case when two values are different.
STAssertEquals(value_1, value_2, failure_description, ...)
Parameters
value_1
(Optional) A comma-separated list of arguments to substitute into failure_description. Detail The test fails when value_1 is not equal to value_2.
STAssertEqualsWithAccuracy
Fails the test case when the difference between two values is greater than a given value.
88
Equality Tests
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
APPENDIX B
Parameters
value_1
(Optional) A comma-separated list of arguments to substitute into failure_description. Detail The test fails when the difference between value_1 and value_2 is greater than accuracy.
Nil Tests
STAssertNil
Fails the test case when a given expression is not nil.
STAssertNil(expression, failure_description, ...)
Parameters
expression
Expression to test.
failure_description
Nil Tests
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
89
APPENDIX B
STAssertNotNil
Fails the test case when a given expression is nil.
STAssertNotNil(expression, failure_description, ...)
Parameters
expression
Expression to test.
failure_description
Boolean Tests
STAssertTrue
Fails the test case when a given expression is false.
STAssertTrue(expression, failure_description, ...)
Parameters
expression
Expression to test.
failure_description
STAssertFalse
Fails the test case when a given expression is true.
STAssertFalse(expression, failure_description, ...)
Parameters
90
Boolean Tests
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
APPENDIX B
expression
Expression to test.
failure_description
Exception Tests
STAssertThrows
Fails the test case when an expression doesnt raise an exception.
STAssertThrows(expression, failure_description, ...)
Parameters
expression
Expression to test.
failure_description
STAssertThrowsSpecific
Fails the test case when an expression doesnt raise an exception of a particular class.
STAssertThrowsSpecific(expression, exception_class, failure_description, ...)
Parameters
expression
Expression to test.
exception_class
An exception class.
Exception Tests
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
91
APPENDIX B
failure_description
(Optional) A comma-separated list of arguments to substitute into failure_description. Detail The test fails when expression doesnt raise an exception of the class exception_class.
STAssertThrowsSpecificNamed
Fails the test case when an expression doesnt raise an exception of a particular class with a given name.
STAssertThrowsSpecificNamed(expression, exception_class, exception_name, failure_description, ...)
Parameters
expression
Expression to test.
exception_class
An exception class.
exception_name
(Optional) A comma-separated list of arguments to substitute into failure_description. Detail The test fails when expression doesnt raise an exception of the class exception_class with the name exception_name.
STAssertNoThrow
Fails the test case when an expression raises an exception.
STAssertNoThrow(expression, failure_description, ...)
92
Exception Tests
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
APPENDIX B
Parameters
expression
Expression to test.
failure_description
STAssertNoThrowSpecific
Fails the test case when an expression raises an exception of a particular class.
STAssertNoThrowSpecific(expression, exception_class, failure_description, ...)
Parameters
expression
Expression to test.
exception_class
An exception class.
failure_description
(Optional) A comma-separated list of arguments to substitute into failure_description. Detail The test fails expression raises an exception of the class exception_class.
STAssertNoThrowSpecificNamed
Fails the test case when an expression doesnt raise an exception of a particular class with a given name.
STAssertNoThrowSpecificNamed(expression, exception_class, exception_name, failure_description, ...)
Parameters
expression
Exception Tests
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
93
APPENDIX B
Expression to test.
exception_class
An exception class.
exception_name
(Optional) A comma-separated list of arguments to substitute into failure_description. Detail The test fails when the expression raises an exception of the class exception_class with the name exception_name.
STAssertTrueNoThrow
Fails the test case when an expression is false or raises an exception.
STAssertTrueNoThrow(expression, failure_description, ...)
Parameters
expression
Expression to test.
failure_description
STAssertFalseNoThrow
Fails the test case when an expression is true or raises an exception.
STAssertFalseNoThrow(expression, failure_description, ...)
Parameters
expression
94
Exception Tests
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
APPENDIX B
Expression to test.
failure_description
Exception Tests
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
95
APPENDIX B
96
Exception Tests
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
APPENDIX C
This appendix contains information about the frameworks and system libraries in the iPhone Simulator SDK. Where applicable, the tables in this index list any key prefixes used by the classes, methods, functions, types, or constants of the framework. You should avoid using any of the specified prefixes in your own symbol names.
SDK version you are using. The First available column lists the iPhone OS release in which the framework first appeared. Important: The frameworks designated as Mac OS Xspecific are used internally by iPhone Simulator. You must not link against these frameworks. Table C-1 Name iPhone Simulator frameworks First Prefixes available 2.0
cblas, vDSP, vv
Description
Accelerate.framework
(Mac OS Xspecific) A utility framework used internally by iPhone Simulator. Do not link to this framework from your applications. Contains functions for accessing the users contacts database directly. Contains classes for displaying the system-defined people picker and editor interfaces.
AddressBook.framework
2.0
AB
AddressBookUI.framework 2.0
AB
97
APPENDIX C
Name
Description
ApplicationServices.framework
(Mac OS Xspecific) Contains a pointer to the Core Graphics framework. Do not link to this framework from your applications. Contains the interfaces for handling audio stream data and for playing and recording audio. Contains the interfaces for loading and using audio units. Contains interfaces for recording and playing audio. (Mac OS Xspecific) A utility framework used internally by iPhone Simulator. Do not link to this framework from your applications.
AudioToolbox.framework
2.0
AU, Audio
AudioUnit.framework
2.0
AU, Audio
AVFoundation.framework
2.2
AV
Carbon.framework
3.0
AE, AH, AS, AX, CM, FC, HI, HM, HR, IB, ICA, KC, KL, LM, Nav, NM, OSA, PM, Sec, Snd, SPB, SR, TE, TSM, TXN, URL CF
CFNetwork.framework
2.0
Contains interfaces for accessing the network via the WiFi and cellular radios. Contains high-level audio interfaces. Contains interfaces for managing object graphs and persistence. Provides fundamental software services, including abstractions for common data types, string utilities, collection utilities, resource management, and preferences. Contains the interfaces for Quartz 2D. Contains the interfaces for determining the users location. (Mac OS Xspecific) A utility framework used internally by the simulator. Do not link to this framework from your iPhone applications. (Mac OS Xspecific) A utility framework used internally by the simulator. Do not link to this framework from your iPhone applications.
CoreAudio.framework CoreData.framework
2.0 3.0
Audio NS
CoreFoundation.framework 2.0
CF
CoreGraphics.framework CoreLocation.framework
2.0 2.0
CG CL
CoreServices.framework
2.0
CF
DiskArbitration.framework
2.0
N/A
98
APPENDIX C
Name
Description
ExternalAccessory.framework Foundation.framework
Contains interfaces for for communicating with accessories attached to an iPhone or iPod touch. Contains the classes and methods for the Cocoa Foundation layer. Contains interfaces for for creating BlueTooth connections between two devices and hosting voice chat services over any network. (Internal) A utility framework used internally by iPhone OS. Do not link to this framework from your applications. (Mac OS Xspecific) A utility framework used internally by the simulator. Do not link to this framework from your applications. (Mac OS Xspecific) A utility framework used internally by the simulator. Do not link to this framework from your applications. Contains interfaces for embedding (and annotating) maps directly into your windows and views. Also provides support for performing reverse-geocoding lookups to determine placemark information for a given map coordinate. Contains interfaces for playing full-screen video. Contains view-controller-based interfaces for composing email messages. Provides access to standard types and constants. Use in conjunction with other frameworks that rely on UTI type information. Contains the interfaces for OpenAL, a cross-platform 3D audio delivery library. Contains the interfaces for OpenGL ES, which is an embedded version of the OpenGL cross-platform 2D and 3D graphics rendering library. Contains the Core Animation interfaces.
2.0
NS
GameKit.framework
3.0
GK
IOKit.framework
2.0
N/A
JavaVM.framework
3.0
N/A
Kernel.framework
3.0
IO
MapKit.framework
3.0
MK
MediaPlayer.framework MessageUI.framework
2.0 3.0
MP MF
MobileCoreServices.framework
3.0
UT
OpenAL.framework
2.0
AL, al
OpenGLES.framework
2.0
GL, gl
QuartzCore.framework
2.0
CA
99
APPENDIX C
Name
Description
QuickTime.framework
(Mac OS Xspecific) A utility framework used internally by the simulator. Do not link to this framework from your applications.
Security.framework
2.0
Contains interfaces for managing certificates, public and private keys, and trust policies. Contains interfaces that allow an application to request payment from a user for additional application functionality or content. Contains interfaces for determining the network configuration of a device. Contains classes and methods for the iPhone application user-interface layer.
StoreKit.framework
3.0
SK
SC
2.0
UI
SDK version you are targeting. For example, the shared libraries for the iPhone Simulator 3.0 SDK would be located in the
<Xcode>/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/lib
The iPhone Simulator SDK uses symbolic links to point to the most current version of most libraries. When linking to a dynamic shared library, use the symbolic link instead of a link to a specific version of the library. Library versions may change in future versions of the iPhone Simulator SDK; if your software is linked to a specific version, that version might not always be available in future releases.
100
Glossary
active build configuration The build configuration used to build a product. See also build configuration. active SDK The SDK used to build a product and the runtime environment on which the product is to run. See also SDK family. application ID A string that identifies an iPhone application or a set of iPhone applications from one vendor. They are similar to bundle identifiers. This is an example application ID: GFWOTNXFIY.com.mycompany.MyApp. base SDK Project setting that specifies the default SDK to use when building the projects targets. Targets can override this setting with the iPhone OS Deployment Target build setting. build configuration A named collection of build settings that build one or more products in a project in different for specific purposesfor example, for debugging or for release. certificate signing request (CSR) File that contains personal information used to generate a development certificate. Certificate signing requests are created by the Keychain Access application. code completion A shortcut that automatically suggests likely completions as you type an identifier or a keyword. The suggestions are based on the text you type and the surrounding context within the file. development certificate File that identifies an iPhone application developer. Xcode uses development certificates to sign application binaries. entitlement A property that allows an application to access a protected iPhone OS feature or capability.
instrument A data-gathering agent developed using the Instruments application. Instruments collect performance information about an application or an entire system. Instruments application A performance analysis tool used to gather and mine application-performance data. iPhone Dev Center An Apple developer center that provides all the resources needed to develop iPhone applications. Access to this developer center requires an ADC membership. See also Apple Developer Connection. iPhone Developer Program A program that allows you to develop iPhone applications, test them on devices, and distribute them to your customers through the App Store. iPhone Developer Program Portal A restricted-access area of the iPhone Dev Center that allows you to configure devices to test your iPhone applications iPhone Simulator application An application that simulates the iPhone OS runtime environment and user experience in Mac OS X for testing iPhone applications in early stages of development. project window A window that displays and organizes the files that make up an Xcode project. provisioning profile A file that allows applications in development to be installed on an iPhone OSbased device. It contains one or more development certificates, an application ID, and one or more device IDs
101
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
GLOSSARY
SDK family Group of SDK releases used to build software products for a particular Apple platform. The available SDK families are iPhone Device SDK, iPhone Simulator SDK, and Mac OS X SDK. test case A piece of code that executes test-subject code to verify that it behaves as expected. test-case method An instance method of a unit-test class named test... that exercises API to test and reports whether it produced the expected results. test provisioning profile A provisioning profile issued to users not on an iPhone application developer team. It allows them to install and test applications that have not been published to the App Store. test suite A set of test cases. See also test case. Xcode A set of tools and resources used to develop iPhone and Mac applications. Xcode application The main application of the Xcode integrated development environment (IDE). It manages the other applications that are part of Xcode and provides the main user interface used to develop software products.
102
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
REVISION HISTORY
This table describes the changes to iPhone Development Guide. Date 2009-08-06 Notes Added information about editing property-list files, linking static libraries, and iPhone Simulator versions. Made minor changes. Added "Editing Property-List Files" (page 25). Added important information about debugging applications on devices to "Debugging Facilities Overview" (page 57). Added "Setting the Simulation-Environment iPhone OS Version" (page 43). 2009-05-28 Described how to set the architecture for which an application is built. Added "Setting the Architecture" (page 35) to describe how to choose the architectures an application can be built for. 2009-05-14 Added unit-testing information and streamlined build workflow. Added "Unit Testing Applications" (page 61). Added "iPhone Simulator Frameworks and Libraries" (page 97). Updated "Running Applications" (page 31) with streamlined build workflow. Added information about restoring application data from a backup. 2009-04-08 Added information on creating entitlement property-list files. Made minor content reorganization. Added "Managing Application Entitlements" (page 27). 2009-03-04 2009-02-04 Made minor content changes. Made minor content changes. Updated "Capturing Screen Shots" (page 54) to specify how to get PNG files of screen shots captured in the Organizer. Updated "Building Your Application" (page 38) with application ID build-error information. 2009-01-06 Made minor content additions. Explained that iPhone Simulator binaries can be used on only one release of the simulator.
103
2009-08-06 | 2009 Apple Inc. All Rights Reserved.
REVISION HISTORY
Date 2008-11-14
Notes Added information about new iPhone Simulator features. Added "Adding the iTunes Artwork to Your Application" (page 76). Added information about the Simulate Memory Warning and Toggle In-Call Status Bar commands to "Manipulating the Hardware" (page 43). Added "Core Location Functionality" (page 45). Added information about using static libraries in iPhone applications to "Creating an iPhone Project" (page 12).
2008-10-15
New document that describes how to develop iPhone applications using Xcode. Incorporates content previously published in iPhone OS Programming Guide and iPhone Simulator Programming Guide.
104
2009-08-06 | 2009 Apple Inc. All Rights Reserved.