through a custom script i update my CFBundleVersion in my app-info.plist when I build and run the app. This information is used as well in the app to display the app name and version. The update works fine in the build process, but the unfortunatly the old information is read in the app itself.
E.g. When I build and run the app the app-info.plist is updated, the CFBundleVersion
has now the value 8
, but in the simulator the value 7
is shown.
Seems so that the updated app-info.plist is not used in the build process, instead the old version is used.
How can I ensure that the updated app-info.plist is used in my app? On the one hand somehow the execution of the script should be the first thing in the build-process or on the other hand the app-info.plist should be renewed in the build process. But for both I do not know how to do this...
I added the custom script under Project > Buildphases > Add Build Phase > Add Run Script. With the following contents:
shell: /bin/bash Tools/addVersionNumber.sh
#/bin/bash
# script that should be executed in the build phase
# to set the build number correct
plist="app-folder/app-Info.plist"
## get git information
# git_rev_full_hash=$( git rev-parse HEAD )
git_amount_commits=$( git rev-list HEAD | wc -l )
git_rev_short_hash=$( git rev-parse --short HEAD )
buildRevision="$git_amount_commits: $git_rev_short_hash"
# set build revision ( git short hash - amount of commits )
/usr/libexec/PlistBuddy -c "Set :BuildRevision $buildRevision" $plist""
## build number
buildNumber=$( /usr/libexec/PlistBuddy -c "Print CFBundleVersion" $plist )
buildNumber=$(( $buildNumber + 1 ))
# set new build number
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" $plist
cheers -- jerik
Found a solution. The trick was that the info.plist in the build folder and the plist in dsym (?) has to be updated as well.
My runscript looks now like this
#/bin/bash
# script that should be executed in the build phase
# to set the build number correct
#
# http://www.cimgf.com/2008/04/13/git-and-xcode-a-git-build-number-script/
# http://stackoverflow.com/questions/7944185/how-to-get-xcode-to-add-build-date-time-to-info-plist-file
# http://www.danandcheryl.com/2012/10/automatic-build-numbers-for-ios-apps-using-xcode
# Marketing Number is in CFBundleShortVersionString - will be edited manually
# @TODO add logging
plist="app-folder/app-Info.plist"
build_plist=$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH
conInfo="Contents/Info.plist"
dsym_plist=$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/$conInfo
function writePlist( ) {
# set build revision ( git short hash - amount of commits )
/usr/libexec/PlistBuddy -c "Set :BuildRevision $buildRevision" $1
# set build date
/usr/libexec/PlistBuddy -c "Set :BuildDate $buildDate" $1
#set build number
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" $1
}
# git_rev_full_hash=$( git rev-parse HEAD )
buildRevision=$( git rev-parse --short HEAD )
git_rev_plist_hash=$( /usr/libexec/PlistBuddy -c "Print BuildRevision" $plist )
# Only update version if a commit was performed. Avoid update version when in development cycle
if [[ $git_rev_plist_hash != $buildRevision ]]; then
### variables for updating plist
# set new build number and date
buildNumber=$( /usr/libexec/PlistBuddy -c "Print CFBundleVersion" $plist )
buildNumber=$(( $buildNumber + 1 ))
buildDate=$(date "+%Y-%m-%d %T %z %Z")
writePlist $plist
writePlist $build_plist
writePlist $dsym_plist
fi
cheers -- jerik