One of the most common tasks when developing iPhone apps is to set up your environment in order to deploy your apps directly to a device (it’s always an exciting moment to see your app run on a phone for the first time!). If you don’t do it every day, it’s easy to forget the steps, especially as there are certificates involved. As a reminder for future reference (and to hopefully help some people out there), here are the steps I like to follow:
1) Make sure that your environment is up to date: The most recent version of Xcode and iOS SDKs require the latest Mac operating systems. Upgrade to Lion (pro-tip: once you buy MacOSX Lion, you can upgrade every device that you own). Get all the security updates for Lion. Update to the latest version of iTunes, Xcode and iOS SDK.
Update: As Mitch Amihod pointed out, Appcelerator’s official recommendation dated March 16th is to either downgrade to Xcode v.4.2.1 or living on the edge with Xcode 4.3 (which doesn’t contradict my recommendation to use Xcode 4.2 w/ iOS 5.0 SDK). If I encounter any problems, I’ll have to test out Xcode 4.2.1.
2) Clean up your Apple development certificates. Once you become a member of the Apple iOS Developer Program, you can access the iOS Provisioning portal and create development certificates for both Xcode and Titanium Studio. What commonly happens is that you’ll create development certificates that you will not use right away, and they will get invalidated over time. If you try to use these old expired certificates, you’ll get all sorts of error messages trying to deploy apps to your iPhone. Here are the steps to clean up your certificates (originally posted on StackOverflow):
- Close all applications, except your web page logged into the iOS Provisioning Portal.
- Open Xcode. Click on the Window > Organizer option, and select “Provisioning Profiles” on the left. This should bring up your provisioning profiles.
- Highlight all your developer profiles, right click and delete them.
- Go back to the browser to the iOS Provisioning Portal (don’t use the “Launch Assistant” just yet).
- Click on Certificates at the left. You will probably have just one line listed with your name/company. Click on Revoke, then click OK to verify.
- Click on Devices. Select all the devices you want to remover, then click OK to verify.
- Wait about two minutes to let Apple to refresh their server backend.
- Click on Home on the left side navigation.
- Click on “Launch Assistant“
- Create a new application ID – call it whatever you want, just make it unique & avoid using IDs you’ve used in the past (important).
- Follow the instructions provided by the Assistant wizard till the end. The main thing you accomplished was deleting your old provision profiles and start over fresh – doing so will make the deployment process less prone to mess up.
3. Add your .mobileprovision certificate to Titanium Studio. A lot of people get messed up by this step – when you launch your app to a device in Titanium Studio, this screen will appear:
Despite what it says, ignore the “Register your iOS device with Apple” and “Obtain Development Provisioning Profile from Apple” steps – you’ve already done both using the Launch Assistant on the iOS Provisioning Portal in step 2! Click on the blue “Upload” link next to “Upload Development Provisioning Profile” and select the .mobileprovision developer certificate you generated & downloaded in step 2 (as instructed by the Launch Assistant). This is quite confusing step – let’s hope the Titanium team cleans up this UI in a future release of the IDE!
4. Configure and set up iTunes. Titanium Studio uses iTunes sync to transfer your custom apps to your iPhone. In order to get it working correctly, you need to set up the Sync Apps option (which will synchronize all your iPhone apps with your development computer). The kicker is that if your development environment isn’t one of your computers you authorized with iTunes, you run the risk of losing & having to redownload/organize apps on your iPhone. To avoid this, select File > Transfer Purchases from “x iPhone” to backup your apps .ipa files.
Be sure to read part 2 of this blog post “Troubleshooting Appcelerator Titanium and iPhone iOS 5.1” to learn what SDK bits to install to properly set your dev environment!