How can I prevent using the Settings.bundle in Rel

2019-03-20 15:31发布

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 bundle resources building phase?

3条回答
在下西门庆
2楼-- · 2019-03-20 16:15

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

查看更多
劳资没心,怎么记你
3楼-- · 2019-03-20 16:21

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"

查看更多
仙女界的扛把子
4楼-- · 2019-03-20 16:31

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
查看更多
登录 后发表回答