实现xcode编译时自动修改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)

 

    原文作者:JoXu
    原文地址: https://blog.csdn.net/book_1992/article/details/111384630
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞