Dynamic Provisioning Profiles with Fastlane

James Pang
Tech with Pangers
Published in
2 min readFeb 3, 2017

When it comes to deploying mobile applications, Fastlane has been an amazing tool that allows new builds to be created in no time. Especially with the Code Signing dance that all iOS developers will encounter at one point or another, it can be a really time consuming process if done manually. Even with all the convenience that Fastlane brings, there are a still a few things that can be tricky, such as applying different provisioning profiles for different builds of an iOS application.

The Fastlane documentation explains how to setup your Xcode project so that the Fastlane action `gym` is able to use the correct provisioning profile. However if you are creating multiple builds of an application, the problem with the approach in the documentation is that it assumes all the builds use the same provisioning profiles — very often this is not going to be the case. You may have an adhoc build, an app store build and then even another adhoc build with a completely different apple ID! That’s three different provisioning profiles you need `gym` to be able to build with. But how?

Walking through the steps in the code snippet above:

  1. A configuration file containing information about the schemes to build is parsed. The schemes variables will be an array of hash tables where each hash table has all the details regarding a single build.
  2. Iterate through each hash table/build.
  3. Set the relevant environment variables for the given scheme hash table.
  4. Perform the `sigh` action, saving the UUID of the provisioning profile that was generated/retrieved.
  5. This is the special sauce: Perform `gym` by passing an xcargs with `PROVISIONING_PROFILE_SPECIFIER` with the value of the provisioning profile UUID that was just generated in step 4. If Xcode 7 or below is used, use `PROVISIONING_PROFILE` instead of `PROVISIONING_PROFILE_SPECIFIER`.

Using the xcargs parameter of `gym` we are able to dynamically change which provisioning profile is used as each scheme is built into an ipa file. This provides a solution to the very common problem of different schemes requiring different provisioning profiles to be code signed correctly.

--

--