if you try to set this value in the build phase of the Xcode compilation, you may have problems, since I do not know that any interpreting operation is performed with the settings that you are trying to configure as you are trying to configure them.
to automatically set the version number, I have a much more complicated scheme with a semi-automatic version and automatic numbering, so I don’t need to remember the change, or I can give the version number that I want but always increase the build number, and in both cases it will put build number in the "About" field in the application settings, which are displayed in the iOS system settings.
you may not need most of this, but there are a few tricks to getting and recording information that may be useful and may lead to a solution to your problem.
The following scenarios were inspired by the response to a stack overflow, how to do this, which I cannot find at the moment. I added a little more work, because (a) I want the version number to be displayed in the settings displayed in the system settings; and (b) Xcode caches the contents of the Info.plist file, so this is not as easy as I expected.
in the build phase that appears before compilation, I run the following (since running the script only during installation is unchecked)
sh xolawareStashProductSettings.sh
the contents of xolawareStashProductSettings.sh checks the status of the git file of the info.plist file, and if it is not clean, temporarily set it aside for later recovery.
#!/bin/sh
script # 2 (with running the script only during installation is not checked):
sh xolawareStashSettingsBundleRootPlist.sh
the contents of xolawareStashSettingsBundleRootPlist.sh are similar to the contents of script 1.
#!/bin/sh
script # 3 (with Run script only during installation )
sh xolawareIncrementProductSettingsBuildNumber.sh
the contents of xolawareIncrementProductSettingsBuildNumber uses plistbuddy to see what it is and raise it by one:
#!/bin/sh # # this should be prior to xolawareAboutInfoVersionInfoInSettings.sh echo "-- Auto-Increment ${INFOPLIST_FILE} Build Version Install Script --" PLISTBUDDYCMD="/usr/libexec/PlistBuddy -c" CONFIGURATION_BUILD_SETTINGS_PATH=${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH} CFBV=$(${PLISTBUDDYCMD} "Print :CFBundleVersion" ${PRODUCT_SETTINGS_PATH}) if [[ "${CFBV}" == "" ]]; then echo "No build number in ${PRODUCT_SETTINGS_PATH}" exit 2 fi CFBV=$(expr $CFBV + 1) set -e echo ${PLISTBUDDYCMD} "Set :CFBundleVersion $CFBV" "${PRODUCT_SETTINGS_PATH}" ${PLISTBUDDYCMD} "Set :CFBundleVersion $CFBV" "${PRODUCT_SETTINGS_PATH}" echo ${PLISTBUDDYCMD} "Set :CFBundleVersion $CFBV" "${CONFIGURATION_BUILD_SETTINGS_PATH}" ${PLISTBUDDYCMD} "Set :CFBundleVersion $CFBV" "${CONFIGURATION_BUILD_SETTINGS_PATH}"
script # 4 (since running the script only during installation is not installed)
sh xolawareProductSettingsShortVersion-from-git.sh sh xolawareAboutInfoVersionInfoInSettings.sh
the contents of xolawareProductSettingsShortVersion-from- git relies a bit on the fact that I mark my branch in git accordingly, but if I forget, it will use the number of commits since the last commit to automatically version my build for me.
#!/bin/sh # # this should be run after xolawareStashSettingsBundleRootPlist.sh # and prior to xolawareAboutInfoVersionInfoInSettings.sh echo '-- Get Product Settings Short Version String from git describe --' PLISTBUDDYCMD="/usr/libexec/PlistBuddy -c" CONFIGURATION_BUILD_SETTINGS_PATH=${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH} CFBVS=`git describe|awk '{split($0,a,"-"); print a[1]}'` CFBVSI=`git describe|awk '{split($0,a,"-"); print a[2]}'` if [[ "$CFBVSI" != "" ]]; then CFBVS=${CFBVS}.${CFBVSI} fi set -e echo ${PLISTBUDDYCMD} "Set :CFBundleShortVersionString $CFBVS" "${PRODUCT_SETTINGS_PATH}" ${PLISTBUDDYCMD} "Set :CFBundleShortVersionString $CFBVS" "${PRODUCT_SETTINGS_PATH}" echo ${PLISTBUDDYCMD} "Set :CFBundleShortVersionString $CFBVS" "${CONFIGURATION_BUILD_SETTINGS_PATH}" ${PLISTBUDDYCMD} "Set :CFBundleShortVersionString $CFBVS" "${CONFIGURATION_BUILD_SETTINGS_PATH}"
contents xolawareAboutInfoVersionInfoInSettings.sh put the contents in the "O" field in my Root.plist as I want. it relies on the “O” field, which is the first of your settings in your Root.plist. bundle:
#!/bin/sh # # this should be invoked after xolawareStashInfoAndRootPlist.sh, # xolawareIncrementProductSettingsBuildNumber.sh and # xolawareProductSettingsShortVersion-from-git.sh, and before # the regular Copy Bundle Resources Build Phase echo '-- Auto-Insert Version Info In System Settings Script --' PLISTBUDDYCMD="/usr/libexec/PlistBuddy -c" ROOT_PLIST=${PROJECT_DIR}/${PROJECT}/Resources/Settings.bundle/Root.plist CFBSVS=`exec -c ${PLISTBUDDYCMD} "Print :CFBundleShortVersionString" ${PRODUCT_SETTINGS_PATH}` CFBV=`exec -c ${PLISTBUDDYCMD} "Print :CFBundleVersion" ${PRODUCT_SETTINGS_PATH}` set -e echo ${PLISTBUDDYCMD} "Set :PreferenceSpecifiers:1:DefaultValue '${CFBSVS} (b${CFBV})'" ${ROOT_PLIST} ${PLISTBUDDYCMD} "Set :PreferenceSpecifiers:1:DefaultValue '${CFBSVS} (b${CFBV})'" ${ROOT_PLIST}
There are also several cleanup scripts that will run after the compilation, linking, and copying resource phases
sh xolawareStashRestoreSettingsBundleRootPlist.sh
it may not be necessary, but I'm setting up other elements in Root.plist to create releases, so it restores these settings for debugging collections.
#!/bin/sh
and finally, the step of the automatic git repo tag, if I haven’t marked the element myself now:
sh xolawareProductSettings-git-commit-and-tag.sh #!/bin/sh # # this should be run after xolawareAboutInfoVersionInfoInSettings.sh # and xolawareProductSettingsShortVersion-from-git.sh echo "-- ${INFOPLIST_FILE} git commit & tag Install Script --" SCRIPT_VERSION=`/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' ${INFOPLIST_FILE}` SCRIPT_BUILD_NUMBER=`/usr/libexec/Plistbuddy -c 'Print :CFBundleVersion' ${INFOPLIST_FILE}` if [ `git status --porcelain ${SCRIPT_INFO_PLIST}|wc -l` -gt 0 ]; then echo git commit -m '"'version ${SCRIPT_VERSION} build ${SCRIPT_BUILD_NUMBER}'"' ${INFOPLIST_FILE} git commit -m "version ${SCRIPT_VERSION} build ${SCRIPT_BUILD_NUMBER}" ${INFOPLIST_FILE} fi echo git tag -f ${SCRIPT_VERSION} git tag -f -F /dev/null ${SCRIPT_VERSION}