Modifying the iOS Settings.bundle using build phases

Most iOS apps today communicate with a server to send and receive data. During development you may have several servers (QA, Staging, Prod) and oftentimes find that you need to distribute copies of your app pointing to each server.A common approach here is to create a temporary “debug” page where you can configure which server you want your app to use.This is a good solution but a more elegant one exists. The idea is to create a settings page in the iOS settings app (iOS Settings.bundle), where you can select between servers or enter your own custom URL. This solution keeps debug code down to a minimum and is less disruptive not requiring an entire debug page created in the app.

Settings.bundle

In order to add an app setting page to the iOS settings app, you must create a Settings.bundle file.

Build Phase Run Script

The problem with the above solution is that you must remember to remove the Settings.bundle file when archiving your app for the store.

Taking our solution to the next level, during an App Store build, the build phases run script can be used to zap this settings page and replace it with something useful. For the purpose of this blog, we will replace the page with the version number of the app.

Below is an example build phase run script that deletes the current settings when building for the App Store and creates new elements for displaying the app version number:

Note that as an added benefit, using the Settings.bundle (even if it is just displaying your app version) is a good way to widen the footprint and exposure of your app since it will be listed in the main settings page.