NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
Build版本获取
NSString *build = [infoDictionary objectForKey:@"CFBundleVersion"];
编写脚本使Archive后自动增加build版本号
如果我们想在Archive后build号自动增长,就可以使用到Xcode的run script来实现,
步骤是:
这段shell脚本的意思就是说,如果当前的配置是Debug(Archive时该值为Release,直接在模拟器上运行是Debug),就设置build值为当前build值+1.(这里为了测试就用Debug)
在开发中一搬都是Release,直接把Debug 改为Release,这样每次打包发布的时候就会自增1.
代码如下
if [ $CONFIGURATION == Release ]; then
echo "Bumping build number..."
plist=${PROJECT_DIR}/${INFOPLIST_FILE}
#increment the build number (ie 115 to 116)
buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}")
if [[ "${buildnum}" == "" ]]; then
echo "No build number in $plist"
exit 2
fi
buildnum=$(expr $buildnum + 1)
/usr/libexec/Plistbuddy -c "Set CFBundleVersion $buildnum" "${plist}"
echo "Bumped build number to $buildnum"
else
echo $CONFIGURATION " build - Not bumping build number."
fi