我试图弄清楚如何在我的 Xcode 4 项目中自动增加 Bundle 版本号(用于临时和发布版本)。我在网上找到了一些声称可以执行此操作的脚本,但我不确定是将它们放在“前置操作”还是“后置操作”中。我也不确定我应该在 plist 中放置什么值;然后脚本将更改的数字或变量?
到目前为止,我尝试过的所有选项似乎都不起作用,因此我们将不胜感激。
以下是我尝试使用的最新脚本:
conf=${CONFIGURATION}
arch=${ARCHS:0:4}
# Only increase the build number on Device and AdHoc/AppStore build
if [ $conf != "Debug" ] && [ $conf != "Release" ] && [ $arch != "i386" ]
then
buildPlist=${INFOPLIST_FILE}
buildVersion=$(/usr/libexec/PlistBuddy -c "Print CFBuildVersion" $buildPlist)
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBuildNumber" $buildPlist)
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBuildNumber $buildNumber" $buildPlist
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildVersion.$buildNumber" $buildPlist
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $buildVersion.$buildNumber" $buildPlist
fi
最佳答案
1,将 CFBundleVersion 设置为 1.0.1 或类似 x.x.x
2、添加构建阶段以运行shell脚本autoVersion.sh
3、保存下面名为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、运行shell:cp autoVersion.sh ~/Documents/and chmod 777 ~/Documents/autoVersion.sh
5,构建并享受它。 :)
perl 代码来自:https://gist.github.com/1436598
https://stackoverflow.com/questions/6286937/