How to auto-increment Bundle Version in Xcode 4? How to auto-increment Bundle Version in Xcode 4? ios ios

How to auto-increment Bundle Version in Xcode 4?


1, Set CFBundleVersion to 1.0.1 or something like x.x.x

1

2, Add build phases to run shell script autoVersion.sh

2

3, save below script named autoVersion.sh

#!/bin/sh# Auto Increment Version Script# set CFBundleVersion to 1.0.1 first!!!# the perl regex splits out the last part of a build number (ie: 1.1.1) and increments it by one# if you have a build number that is more than 3 components, add a '\.\d+' into the first part of the regex.buildPlist=${INFOPLIST_FILE}newVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist" | /usr/bin/perl -pe 's/(\d+\.\d+\.)(\d+)/$1.($2+1)/eg'`#echo $newVersion;/usr/libexec/PListBuddy -c "Set :CFBundleVersion $newVersion" "$buildPlist"

4, run shell: cp autoVersion.sh ~/Documents/ and chmod 777 ~/Documents/autoVersion.sh

5, Build & Enjoy it. :)

perl code from: https://gist.github.com/1436598


You may find the following post helpful:

Auto-Incrementing Build Numbers for Release Builds in Xcodefrom iPhone Developmentby Jeff LaMarchehttp://iphonedevelopment.blogspot.com/2011/07/auto-incrementing-build-numbers-for.html


The same idea as Alix's answer, but much simpler:

buildNumber=`/bin/date +%Y%m%d%H%M%S`/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"

Add this as a Run Script item on Build Phases on your Target. This has the advantage of being monotonically increasing as well.


matomo