With iPhone Simulator you can start developing iPhone applications without using iPhone OS–based 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, doesn’t allow you to run applications on iPhone OS–based devices. To do so you must be a member of the iPhone Developer Program. See “Accessing the iPhone Developer Program Portal” 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 application’s 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.
The iPhone Developer Program provides the tools and resources you need to run applications on development devices and distribute them to iPhone OS users. To become a member of the iPhone Developer Program, visit http://developer.apple.com/iphone/program.
After becoming an iPhone Developer Program member, you have access to the iPhone Developer Program Portal in the iPhone Dev Center. The iPhone Developer Program Portal (or Program Portal) is a restricted-access area of the iPhone Dev Center that allows you to configure devices to test your iPhone applications on them.
Important: If you are not a member of the iPhone Developer Program, you do not have access to the Program Portal.
In order to test your application on a device, you must configure your computer and your device for iPhone OS development. This section presents an overview of the process and provides detailed information in the sections that follow.
In preparing your device for development, you create or obtain the following digital assets:
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.
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.”
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 you’re 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.
These are the requirements your computer and your development device must meet so that you can build iPhone applications that run on your device:
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:
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.
The following sections describe these tasks in detail.
After becoming a member of the iPhone Developer Program (see “Accessing the iPhone Developer Program Portal”), you must set your application ID in the Program Portal. iPhone OS uses application IDs to identify the applications you create. An iPhone application ID is made up of a ten-character bundle seed identifier and a bundle identifier. The bundle identifier can identify one application or a group of applications.
This is an example of an iPhone application ID that identifies a single application, named MyApp:
GFWOTNXFIY.com.mycompany.MyApp |
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.* |
To register your development device with the portal:
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.
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.”
To run applications you develop using the iPhone SDK, your device must be running iPhone OS 2.0 or later.
To learn how to install iPhone OS on your device, see “Restoring System Software.”
Xcode uses your development certificate to code-sign your application before it uploads it to your device for testing.
Start by generating a certificate signing request (CSR) on your computer:
Launch Keychain Access, located in /Applications/Utilities.
Choose Keychain Access > Certificate Assistant > Request a Certificate From a Certificate Authority.
In the Certificate Information window:
In the User Email Address field, enter your email address.
In the Common Name field, enter your name.
In the “Request is” group, select the “Saved to disk” option.
Select “Let me specify key pair information.”
Click Continue.
Choose your desktop as the location for the CSR file.
In the Key Pair Information pane, choose 2048 as the key size and RSA as the algorithm.
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 don’t lose your private key and that only you have access to it. Therefore, it’s 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” for more information.
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”). 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” for details.
Your development certificate must be in your keychain so that Xcode can digitally sign your iPhone applications.
To add your development certificate to your keychain, in your computer:
Open your development certificate with the Keychain Access application by double-clicking it or dragging it to the Keychain Access application icon.
In the Add Certificates dialog, ensure Keychain is set to “login” and click OK.
To obtain your provisioning profile:
Have your team admin create your provisioning profile in the Program Portal.
Download your provisioning profile from the Program Portal (see “Accessing the iPhone Developer Program Portal”).
You use the Organizer to add provisioning profiles to your development device.
To add a provisioning profile to Xcode, drag the provisioning profile file to the Xcode icon in the Dock. After this action your provisioning profile appears in the Provisioning Profiles list in the Organizer.
After adding your provisioning profile to the Organizer, you can add it to your device:
Open the Organizer window.
Your provisioning profile should appear in the Provisioning Profiles list. If you don’t see it there, follow the instructions in “Adding Your Provisioning Profile to the Xcode Organizer.”
Plug in your device.
Drag your provisioning profile from the Provisioning Profiles list to your device, under the Devices group in the Organizer sidebar.
Once installed, a checkmark should appear in the checkbox next to the provisioning profile. If the checkmark doesn’t appear, ensure that the provisioning profile includes your device UDID, your development certificate, and a valid application ID. Go to the Program Portal (see “Accessing the iPhone Developer Program Portal”) or contact your team admin to verify that the provisioning profile contains this information . You need to go back to the “Obtaining Your Provisioning Profile” step if changes are made to your profile.
When you develop applications using the iPhone SDK, you should test those applications on devices running the iPhone OS version the SDK targets. You can download the latest release of the iPhone SDK from the iPhone Dev Center. Use iTunes to install the latest iPhone OS onto your device.
To restore a device:
Launch Xcode and open the Organizer window.
Plug the device into your computer.
Select the device in the Devices list.
From the Software Version pop-up menu, choose the version of iPhone OS you want to place on the device.
If you’re using a seed release of the iPhone SDK and the version of iPhone OS you want to install is not listed in the Software Version pop-up menu:
Download the iPhone OS seed that corresponds to your iPhone SDK seed from http://developer.apple.com.
From the Software Version pop-up menu, choose Other Version.
Navigate to the disk image containing the iPhone OS developer software and click Open.
Xcode extracts the iPhone OS software from the disk image. You can dispose of the disk image you downloaded.
From the Software Version pop-up menu, choose the newly downloaded iPhone OS version.
During nonseed periods, you must install iPhone OS using iTunes.
Click Restore iPhone or Restore iPod, depending on your device’s type.
Use iTunes to name your device.
After following the instructions in “Preparing Devices for Development” and “Restoring System Software” (if necessary) you can run your application on your development device.
You tell Xcode that you want to build your application for a device and that you want to run it on a connected device by setting the active SDK to an iPhone Device SDK. See “Building Your Application” for details.
Screen shots help to document your application. This is also how you create your application’s default image, which iPhone OS displays when the user taps your application’s icon. You can capture screen shots of your device’s screen from the Organizer or directly on your device.
To capture a screen shot from the Organizer:
Configure your application’s screen for the screen shot.
Depending on your application’s workflow, you may need to place breakpoint in your code and run your application until it reaches that point.
Open the Organizer window, select your device, and click Screenshots.
Click Capture.
To make that screen shot your application’s default image, click Save As Default Image.
To get a PNG file of the screenshot, drag it to the desktop.
If you have iPhoto installed on your computer, you may capture screen shots directly on your device and import them into your iPhoto library.
To capture a screen shot on your device, press the the Lock and Home buttons simultaneously. Your screen shot is saved in the Saved Photos album in the Photos application.
When you create a certificate signing request (CSR) to obtain your development certificate, you generate a public/private key pair. The public key is included in your development certificate. The private key is stored in your keychain. With these two items in your computer, Xcode can code-sign the iPhone applications you build with it. If you need to use another computer to develop iPhone applications, you must transfer these items to the other computer and add them to your keychain.
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:
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.)
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:
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.
Place the protected disk image in a secure location.
Now, when you need to develop iPhone applications on another computer:
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:
Launch Keychain Access.
Choose File > Import Items.
Choose the private key file to import.
Add the development certificate to your keychain. See “Adding Your Development Certificate to Your Keychain” for details.
Last updated: 2009-08-06