「Xcode」实现提交版本时build号自增

实现build号自增

Posted by Jiaolong on 2021/09/08
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
let appBuild = Bundle.main.infoDictionary?["CFBundleVersion"] as? String

# Type a script or drag a script file from your workspace to insert its path.

# build_version=$(date +%y%m%d%H%M)
# /usr/libexec/PlistBuddy -c "Set CFBundleVersion ${build_version}" ${INFOPLIST_FILE}

if [ $CONFIGURATION == Release ]; then
echo "当前为 Release Configuration,开始自增 Build"
plist=${INFOPLIST_FILE}
buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}")
if [[ "${buildnum}" == "" ]]; then
echo "Error:在Plist文件里没有 Build 值"
exit 2
fi
buildnum=$(expr $buildnum + 1)
/usr/libexec/PlistBuddy -c "Set CFBundleVersion $buildnum" "${plist}"
else
echo $CONFIGURATION "当前不为 Release Configuration"
fi