I need to have a settings.bundle in our debug build, but don\'t want to have it in our Release. How do I approach this? Is there a runscript I can use to remove it from the copy
Found it. I've created a RunScript as the last phase in my build phases. In there, I remove all entries in the settings plist and replace it with a version number. This way, I can use the settings.bundle root.plist as settings for my debug project (to be able to define which test server to use or any other thing that would be specify-able in a debug build). So, when you build debug, the root.plist is what you expect it to be. When you run the Release build, the contents get replaced with the CFBundleVersion information of your info.plist. All debug related choices are gone.
if [ "$CONFIGURATION" = "Release" ] ; then
echo "Replacing $CODESIGNING_FOLDER_PATH/Settings.bundle for 'Release' build"
APPVERSION="`/usr/libexec/PlistBuddy -c \"Print :CFBundleVersion\" \"$CODESIGNING_FOLDER_PATH/Info.plist\"`"
SETTINGSBUNDLEPATH="$CODESIGNING_FOLDER_PATH/Settings.bundle/Root.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"
fi
Alternatively, just don't include the settings bundle in the "Copy Bundle Resources" and add a build phase run script to only include it for certain configs.
Here's a run script that also updates a version and build in the settings bundle
if [ ${CONFIGURATION} == "Debug" ] ; then
echo "Copying settings bundle..."
version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$SRCROOT/Blah/Supporting Files/Info.plist")
build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$SRCROOT/Blah/Supporting Files/Info.plist")
cp -r "${PROJECT_DIR}/Blah/Supporting Files/Settings.bundle" ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
echo "Updating settings bundle version to ${version}b${build}"
/usr/libexec/PlistBuddy "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/Settings.bundle/Root.plist" -c "Set :PreferenceSpecifiers:17
:DefaultValue $version($build)"
fi
making sure to change out the Blah/Supporting Files
path to whatever yours actually is
You can write a script to delete the setting bundle altogether for a certain build configuration. For the target, under "Build Settings", there is an option to run a script. This script should do what you need:
BUILD_APP_DIR=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
if [ "$CONFIGURATION" == "Release" ]; then
rm -Rf $BUILD_APP_DIR/Settings.bundle
echo "Removed Settings Bundle"
fi
The "shell" field can read "/bin/sh"