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

1万+

被折叠的 条评论
为什么被折叠?



