Like a lot of iOS developers, we use TestFlight for our development build process on MapBox for iPad, our iPad app for sharing fast custom maps. TestFlight easily lets you manage teammates, their devices, app builds, and statistics around who is reading about, installing, and reporting issues with your app while it is in development.

One thing that can be tedious, however, is the process of creating an iOS app archive - the bundle that holds your built application, some metadata around the conditions under which it was built, and your .dSYM file, which contains data that is stripped from your shipping app for performance reasons but is used when debugging crashes during development. On top of that, you then need to create an .ipa file, which is the bundle that actually gets placed on iOS devices, and you need to upload it to TestFlight in order to send notifications about it out to your testing team.

Whew! Just writing about all of this process is tedious, let alone actually doing it. So I started working on a way to automate all of it with Xcode 4, allowing you to click Build & Archive in Xcode as normal, wait a while, and be presented with a web page on TestFlight containing your build that’s ready for your testing release notes.

The basic approach is as follows. Warning! Xcode-isms abound.

  1. Create an Archive step Post-action in your main target’s scheme.
  2. Use some shell trickery to find the latest built archive, since this doesn’t get passed to scripts.
  3. Create an .ipa from the archive.
  4. Re-codesign the .ipa for distribution.
  5. Embed the proper provisioning profile that references your testing team’s devices.
  6. Upload the .ipa to TestFlight using their upload API.
  7. Open the build page in your browser.
  8. Log everything along the way.

Keep in mind that this script will end up in your scheme, which you may or may not include in version control. Mine is located in (project).xcodeproj/xcuserdata/(username).xcuserdatad, and we exclude xcuserdata from version control.

The script ends up in a place like this:

Adding an Xcode 4 scheme Archive Post-script

You can get your API token from your TestFlight account page and your team token from editing your team page. Aside from your code signing identity and provisioning profile, which could be the same across all members of your team, these are the only dynamic bits that you’d have to change for multiple developers using this script. In all likelihood, even the team token would be the same.

Once you’ve replaced those two values in the script, be sure to set the script shell to /bin/bash from the default of /bin/sh. Also be sure to select your main app target in the Provide build settings from picker so that the product and target environment variables are set properly.

Now, whenever you choose Product > Archive from Xcode, you will get an archive, then a shippable .ipa from it, it will be uploaded to TestFlight, and you will get a web page where you can set the release notes, choose testers to notify, and be on your way to testing the next great version of your app!

Here’s the script:

Thanks to the following pages, from which I gleaned a good amount of info on how to do this, but which didn’t quite get the job done for me as is:

We're a team of engineers and designers working on big projects. We believe in open source and in building for lasting impact.

Learn more