I've been an iOS developer for some time now and there is one thing that keeps surprising me in an unpleasant way: the process of building, releasing and signing an iOS app with a provisioning profile. I understand the motivation behind this, but I keep cursing the process of going through iOS app development.

Xcode is a powerful tool, but when it comes to the release process it's usually helpless, resulting in a countless number of hours spent searching which part of the signing process failed and how to fix it.

As the number of developer programs I'm involved in grows and the number of provisioning profiles exceeds screen size, the number of problems I'm having grows as well. Every time I solve a problem and learn a piece of this tangled logic, I step upon another and it often seems that the learning process is never-ending.

A while ago, Imaginary Cloud decided that we need to have this process under control. I was asked to find another way of doing things, and I did!

Let me share with you some great solutions to this annoying situation.

Use the terminal

As you probably know, Xcode comes with additional command line tools which can be installed either in the downloads part of Xcode properties or, if you're about to leave its lovely UI in favour of the terminal window anyway, you can start executing the command right away:

xcode-select --install

You now got yourself a UI-less version of your favourite app. It's totally worth it. If you want to learn about its great features you type:

xcodebuild -help

I'll brief you on my favourite two lines that are just enough to clean build, archive, sign with provisioning profile and export your app into a portable .ipa file. The tool is really made simple so the lines are pretty much self-explanatory:

xcodebuild -scheme nameOfTheScheme clean archive

This will clean build the code and archive results into your current archive directory (it'll show up in the Xcode organiser). If you want it in any other place you just specify the custom path:

xcodebuild -scheme nameOfTheScheme clean archive -archivePath path/to/name.xcarchive

Then the following command will export the generated archive into a runnable ipa file, signed with the provisioning profile of your choice:

xcodebuild -exportArchive -archivePath path/to/name.xcarchive -exportPath path/to/name -exportFormat ipa -exportProvisioningProfile "provisioningProfileName"

These two commands alone can save you hours of work, but things can get even better.

The irreplaceable Mattt Thompson wrote his own command line utility on top of xcodebuild to make the whole process even simpler.

Shenzhen is a set of tools for building and distributing iOS Apps. You install it with:

gem install shenzhen

To create a new ipa with default settings, signed with provisioning profile of your choice, you do:

ipa build -m "provisioningProfileName"

It'll generate both ipa and dSYM debug symbol store files for you to upload to any distributing channel. If you don't want to do it manually, here is the best part:

ipa distribute:hockeyapp -a API_TOKEN

I'll package and push a new version straight to HockeyApp, or a similar service, Shenzhen now supports the following: iTunes Connect, HockeyApp, Crashlytics Beta, DeployGate, Fly It Remotely, Amazon S3 and an FTP / SFT host.

It has a wide range of additional options to support all the custom settings you may want to include (discover them with the usual -- help option). It'll also upload the corresponding dSYM file for your crash logs to be readable.

That's it!

The task that was always a Russian roulette for me, is now one that has become a really simple one. I don't know exactly what hides behind the Xcode UI, but it seems that it does not serve the purpose.

This discovery already saved me a lot of time and, unlike the Xcode UI way of doing things, it'll only get better and better.