I’ve been following a Rails convention and defining multiple environments for my iPhone projects. This allows me to quickly switch application wide settings when running a test, development, or production version of the app.
I already have build targets for each environment as part of the unit testing setup I have been using so adding target-specific run-time settings turns out to be quite easy.
I created an “Environments” resource group in Xcode and added a copy of my project’s “Resource/Info.plist” file for each environment.
These plists should not be members of any build target (just like the original Info.plist.
In each build target’s settings I then set the “Info.plist File” to the plist I created for that target’s environment. Note that the path to this file is the actual path on disk relative to the project root; if you have an ‘Environments’ group in the project but no actual ‘Environments’ directory in your project then this path would be incorrect.
In code I can then access the plist’s dictionary via the application bundle:
[[NSBundle mainBundle] infoDictionary]
Now I can define the domain name of an API I will be using in each plist and automatically connect to localhost when running tests, to a staging server when using a development build, and to the production server when building a release or adhoc build. Each environment has it’s own build target so I can also specify a different app product identifier for each target and install the different app versions side by side on the same device.