How to auto-increment Bundle Version in Xcode 4?

后端 未结 9 908
情书的邮戳
情书的邮戳 2020-12-12 16:43

I am trying to figure out how to have the Bundle version number increment automatically in my Xcode 4 project (for ad-hoc and release builds). I found some scripts online th

9条回答
  •  盖世英雄少女心
    2020-12-12 16:53

    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

提交回复
热议问题