Even after you’ve obtained
an Apple Developer Membership, joined a paid Developer Program, and
downloaded and installed the iOS development tools, you still
won’t be able to run on your iPhone any applications that you write!
Why? Because you haven’t created a development provisioning profile yet.
In many development guides,
this step isn’t covered until after development begins. In my mind,
once you’ve written an application, you’re going to want to immediately
run it on the iPhone. Why? Because it’s just cool to see your own code
running on your own device!
What’s a Development Provisioning Profile?
Like it or not, Apple’s
current approach to iOS development is to make absolutely certain that
the development process is controlled—and that groups can’t just
distribute software to anyone they want. The result is a rather
confusing process that ties together information about you, any
development team members, and your application into a “provisioning
profile.”
A development
provisioning profile identifies the developer who may install an
application, an ID for the application being developed, and the “unique
device identifiers” for each iPhone that will run the application. This
is only
for the development process. When you are ready to distribute an
application via the App Store or to a group of testers (or friends!)
via ad hoc means, you’ll need to create a separate “distribution”
profile. Because we’re just starting out, this isn’t something you’
need right away.
Generating and Installing a Development Provisioning Profile
Creating a
provisioning profile can be frustrating and seem outrageously
convoluted. Apple has streamlined the process tremendously with an
online Development Provisioning Assistant, but we still have to jump
through some hoops. Let’s bite the bullet and get through this!
Getting Your iPhone Unique Device Identifier
To run your application
on a real iPhone, you need the ID that uniquely identifies your iPhone
from the thousands of other iPhones. To find this, first make sure that
your device is connected to your computer, and then launch Xcode from
the Developer/Applications folder. When Xcode first launches,
immediately choose Window, Organizer from the menu. The Organizer
utility slightly resembles iTunes in its layout. You should see your
iPhone listed in the far-left column of the Organizer under the Devices
section. Click the icon to select it, and then click the “Use for
Development” button. Your screen should now resemble Figure 1
The Identifier field is the
unique device ID that we’re looking for. Go ahead and copy it to the
Clipboard. You’ll need to paste it into the Provisioning Assistant
shortly.
Starting the Provisioning Assistant
Next, head to the Apple website and the iPhone Dev Center (http://developer.apple.com/iphone).
Make sure that you’ve logged in to the site, and then click the iPhone
Provisioning Portal link, currently located in the upper-right side of
the page. The Provisioning Portal is designed to give you access to the
tools you need to create provisioning and distribution profiles. It
also includes the Development Provisioning Assistant, which is the web
utility that will make our lives much easier. Click the Launch
Assistant button (see Figure 2).
The assistant will launch in your web browser and display a short splash screen. Click the Continue button to begin.
Choosing an App ID
Your first step is to choose
an App ID. This ID will identify a shared portion of the keychain that
your application will have access to.
Come again?
The keychain is a secure
information store on the iPhone that can be used to save passwords and
other critical information. Most apps don’t share a keychain space (and
therefore can’t share protected information). If you use the same App
ID for multiple applications, however, they can share keychain data.
For the purposes of this
book, there’s no reason the tutorial apps can’t share a single App ID,
so create a new ID named anything you want. If you have already created
App IDs in the past, you’ll be given the option to choose an existing
ID. I’m creating a new App ID, Tutorials, as shown in Figure 3. Enter the ID and click Continue to move on.
Assigning a Development Device
Next you are asked to assign a development device, as shown in Figure 4.
This device ID identifies which iPhone will be allowed to run the
applications you create. Enter a meaningful description for the device
(“Johns iPhone,” for example), and then paste the string you copied
from the Xcode organizer into the Device ID field. Click Continue to
move on.
Note that as with the App
IDs, if you’ve already used a device ID in the past, you will be given
the option of simply selecting it from a drop-down list.
Generating a Certificate Signing Request
Now things are getting fun.
The next step takes place outside of your browser. Leaving the
Development Provisioning Assistant open, go to the
Applications/Utilities folder on your hard drive and open the Keychain
Access utility. Choose Keychain Access, Certificate Assistant, Request
a Certificate from a Certificate Authority from the menu (see Figure 5).
The Keychain Access
Certificate Assistant will start. Thankfully, this is a pretty short
process. You just need to enter your email address, name, and highlight
the Saved to Disk option, as shown in Figure 6.
Click Continue to save the
certificate to your disk. Make sure you make a note of where you save
the certificate, because you’re going to be uploading it to Apple back
in the Development Provisioning Assistant. Once you save it, you can
close the Certificate Assistant window.
Uploading the Certificate Signing Request
Return to the
Development Provisioning Assistant in your web browser. Click Continue
until you are prompted to submit the certificate signing request that
you just generated (see Figure 7). Click the Choose File button so that you can select the request file, and then click Continue to upload it.
Naming and Generating the Provisioning Profile
We’re almost done! After uploading the request, you’ll be prompted to name the provisioning profile (see Figure 8).
Because this profile contains information that can potentially identify
individual phones and applications, you should choose something
relevant to how you intend to use it. In this case, I’m only interested
in using it as a generic development profile for all of my apps, so I’m
naming it iPhone Development Profile. Not very creative, but it works.
Click the Generate button to
create your provisioning profile. This may take 20 to 60 seconds, so be
patient. The screen will eventually refresh to show the final profile
information, as shown in Figure 9.
Our final steps will be
downloading and installing the profile, and downloading and installing
a security certificate that will be associated with the profile.
Downloading the Development Provisioning Profile and Certificate
At this point, your profile
has been generated, along with a security certificate that can be used
to uniquely associate your applications with that profile. All that
remains is downloading and installing them. Click the Continue button
to access the provisioning profile download screen, as shown in Figure 10. Click the Download Now button to save the profile to your Downloads folder (file extension .mobileprovision).
As much as I hate to say it,
the next thing to do is to ignore the onscreen instructions—the
installation process that Apple describes in the assistant isn’t the
most efficient route. Instead, click the Continue button until you are
given the option of downloading the development certificate, as shown
in Figure 11.
Click the Download Now
button to download the certificate file (file extension .cer) to your
Downloads folder. You are now finished with the Provisioning Assistant
and can safely exit.
Installing the Development Provisioning Profile and Certificate
To install the profile and
certificate, we just need to exercise our double-click skills. First,
install the development certificate by double-clicking it. Doing so
opens Keychain Access and prompts you for the keychain where the
certificate should be installed. Choose the login keychain, and then
click OK, as demonstrated in Figure 12.
After adding the
certificate, you should be able to browse through your login keychain
for a key labeled with your name that contains the certificate.
To install the
development profile, double-click the downloaded .mobileprovision file.
Xcode will launch—if it isn’t already running—and silently install the
profile. You can verify that it has been successfully installed by
launching the Organizer within Xcode (Window, Organizer) and then
clicking the Provisioning Profiles item within the iPhone Development
section, as shown in Figure 13.
Did you Know?
After you have a development
machine configured, you can easily configure other computers using the
“Developer Profile” item in the Xcode organizer. The “Export Developer
Profile” and “Import Developer Profile” buttons will export (and
subsequently import) all your developer profiles/certificates in a
single package.
The Development Provisioning
Assistant helps you create a provisioning profile for a single iPhone,
iPad, or iPod Touch device. But, what if you have multiple devices that
you want to install onto? No problem. You’ll need to head back to the
iPhone Provisioning Portal and click the Devices link on the left side
of the page. From there, you can add additional devices that will be
available to your profile.
Next, click the Provisioning
link, also on the left side of the page, and use the Edit link to
modify your existing profile to include another iPhone, as demonstrated
in Figure 14.
Finally, you’ll need to
click the Download link to redownload the modified profile and then
import it into Xcode so that the additional device is available.
|
Testing the Profile with an iPhone App
It seems wrong to go through all
of that work without some payoff, right? For a real-world test of your
efforts, let’s actually try to run an application on your iPhone. If
you haven’t downloaded the project files to your computer, now is a
good time to visit http://teachyourselfiphone.com and download the archives.
Within the Hour 1
Projects folder, open the Welcome folder. Double-click
Welcome.xcodeproj to open a simple application in Xcode. After the
project opens, your display should be similar to Figure 15.
Next, make sure that your
iPhone is plugged into your computer. Using the menu in the upper-left
corner of the Xcode window, choose Device 4.0 (or a later version, if
available). This will tell Xcode that when the project is built it
should be installed on your iPhone. Finally, click Build and Run.
Xcode will install the
correct provisioning profile on your device, and, after a few seconds,
the application should be installed and launched on your iPhone, as
seen in Figure 16.
You can now exit Xcode and quit the Welcome application on your iPhone.
By the Way
When you clicked Build and
Run, the Welcome application was installed and started on your iPhone.
It will remain there until you remove it manually. Just touch and hold
the Welcome icon until it starts wiggling, and then delete the
application as you would any other. Applications installed with your
development certificate will stop working when the certificate expires
(120 days after it was issued).