Xcode Project -> TARGETS -> Build Phases -> “+” -> New Run Script Build Phases
在新出现的Run Script栏中, 于Shell输入框中输入如下脚本:
#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
如果想只在非Debug模式下生效,则添加判断:
#!/bin/bash
if [ $CONFIGURATION != Debug ]; then
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
fi
如图所示:
如图所示
网友评论