实现xcode编译时自动修改App的版本号和构建版本号

介绍了在Xcode中设置App版本号和构建号的方法。在Xcode里选中对应targets,选择build phases,点击 + 选“add new run script phases”,在代码编辑区域输入代码,完成添加后,每次编译会将git的tag版本号和提交次数分别赋值给App的版本号和构建号。

在xocde中选中对应targets ,然后选择 build phases 

点击 + ,选择 "add new run script phases"

在展开新加的item,然后在其代码编辑区域输入以下代码:

 

#!/bin/bash

git=$(sh /etc/profile; which git)
git_release_version=$("$git" describe --tags --always --abbrev=0)
number_of_commits=$("$git" rev-list $git_release_version..HEAD --count)

target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH"
dsym_plist="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Info.plist"
src_plist="./$TARGET_NAME/Info.plist"
for plist in "$src_plist"; do
if [ -f "$plist" ]; then
echo "Start to update build number"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $number_of_commits" "$plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${git_release_version}" "$plist"
fi
done

 

完成上面的添加后,每次编译时,都会把git里面tag版本号和git的提交次数,分别赋值给App的版本号(CFBundleVersion)和构建本号(git_release_version)

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值