Configuring iOS app ids at build time.

Working on iOS projects where multiple companies with multiple iOS dev accounts are all editing the same source can be problematic. The biggest problem is managing the provisioning profiles for AdHoc testing distributions. Generally, if each group has their own iOS account, they’ll each need their own app id too. To make things easier, you can configure the app id dynamically when you build the app so that builds on your machine are using different id’s than other’s builds. Here’s how.

First, decide on a naming convention that everyone will follow. I suggest prefix.com.actualid where the prefix portion will differ between development groups. For example, let’s say that the actual app id for distribution is com.mycoolapp. Now, each group should configure an app id such as groupA.com.mycoolapp and groupB.com.mycoolapp.

Next, use a variable in the plist for the application. For example, in your plist define the app id as:

${APP_ID_PREFIX}com.mycoolapp

If you haven’t defined APP_ID_PREFIX in your environment, the app will compile with com.mycoolapp so now have every developer create and environment.plist on their development machines to define this variable. The environment.plist goes in

~/.MacOSX/environment.plist

and should contain the APP_ID_PREFIX key/value pair. For example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>APP_ID_PREFIX</key>
    <string>jeffrey.</string>
</dict>
</plist>

NOTE: You’ll have to log out and log back into your OSX user account for the changes to apply.

Now when I compile the application, it will use jeffrey.com.mycoolapp as the app id. I can define this app id and appropriate provisioning profiles in my iOS dev account and when others compile the code they can define their own.