How can I prevent using the Settings.bundle in Release build v.s. Debug build?

前端 未结 3 721
北恋
北恋 2021-02-09 07:07

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

3条回答
  •  野性不改
    2021-02-09 07:24

    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
    

提交回复
热议问题