Thinking > story

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, 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.


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

Below is a simple example:

			<string>Restart app after making changes</string>
			<string>ON-Dev OFF-Staging</string>
			<string>Other (i.e.</string>

And the resulting settings page:

apple debug settings

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:

if [ "$CONFIGURATION" == "AppStore" ] ; then

APPVERSION="`/usr/libexec/PlistBuddy -c \"Print :CFBundleVersion\" \"$CODESIGNING_FOLDER_PATH/Info.plist\"`"

/usr/libexec/PlistBuddy -c "Delete :PreferenceSpecifiers" "$SETTINGSBUNDLEPATH"

/usr/libexec/PlistBuddy -c "Add :StringsTable string 'Root'" "$SETTINGSBUNDLEPATH"
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers array" "$SETTINGSBUNDLEPATH"
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:0 dict" "$SETTINGSBUNDLEPATH"

/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:0:Type string 'PSGroupSpecifier'" "$SETTINGSBUNDLEPATH"
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:0:Title string 'Version Information'" "$SETTINGSBUNDLEPATH"

/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:1:Type string 'PSTitleValueSpecifier'" "$SETTINGSBUNDLEPATH"
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:1:Title string 'Release:'" "$SETTINGSBUNDLEPATH"
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:1:Key string 'appVersion'" "$SETTINGSBUNDLEPATH"
/usr/libexec/PlistBuddy -c "Add :PreferenceSpecifiers:1:DefaultValue string '$APPVERSION'" "$SETTINGSBUNDLEPATH"


And the resulting settings page:

apple final settings

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.

Recent Posts

Let's talk.

Give Us a Call
(800) 352-2292
Business Inquiries