Thursday, September 22, 2011

Deploying to your iPhone

This article describes the steps to upload the HelloWorld app to your iPhone and test it on actual hardware.

Testing on your iPhone
In Unit Tests IV, we completed our Logic and Application Tests.  Now, some real-world testing on an actual device is in order. Here is how to upload HelloWorld and test it on an actual iPhone:
  • Enroll in the iOS Developer Program
    • $99 annual membership fee.
  • Provision your iPhone for generic development (steps for Xcode 4.2):
    • Open the Xcode Organizer tool (Window > Organizer).
    • In the Library section, select Provisioning Profiles.
    • Check the box at the bottom for Automatic Device Provisioning.
    • Connect your iPhone to your Mac.
    • Click on your iPhone in the Devices section.
    • Click the Add to Portal button at the bottom.
    • When prompted for an iOS Distribution Certificate, click Send Request.
Wait while Xcode communicates with Apple. When it is finished, you should see a new iOS Provisioning Profile in the Library section. (You can also view your Provisioning Profile in the iOS Provisioning Portal at the Apple Developer Member Center.)

Now we can deploy HelloWorld on the device. Before disconnecting your iPhone, do the following in Xcode:
  • Open the Edit Scheme... dialog (Product > Edit Scheme... , or simply ⌘<).
  • Select your iPhone as the destination for the HelloWorld scheme
  • Build the app (⌘B).
  • Run the app (⌘R).
HelloWorld should open on your iPhone while you are still connected to Xcode. Enter your name and confirm the result. You may terminate by clicking the Stop button within Xcode. Now you should see HelloWorld installed on your iPhone:


Disconnect your iPhone at any time. Open the app and confirm it behaves as expected.


Setting the App Icon
HelloWorld is great. Before showing it off to your friends, though, let's add some polish. As one can see in the screen-shot above, the HelloWorld app icon is not "sexy" like the others. It is simply a boring white square.

To set the app icon for HelloWorld, open the project again and navigate to the "Summary" settings in Xcode:
The iOS Human Interface Guidelines specify the app icon should be a 57x57 PNG file. Right-click the empty "App Icon" and then "Select File" to choose an icon for the HelloWorld app. Build and deploy the app to your iPhone again. Now HelloWorld should have a shiny new icon:


Yay! Launch the app and confirm it behaves as expected.