在开发过程中,记录下整个项目build了多少次,有的人觉得有意义,有的人觉得没意义。但我是前者!
如果是单独开发者 这里 的Shell Script就足够了
但是,如果是团队开发者,这样的Script,往往会导致info.plist冲突,而且,build的数目也不对
所以有了以下的解决办法
currentUser="$USER"
cretePlist() {
cat > build.plist <
$currentUser
1
users
$currentUser
EOF
}
[ -f ${PROJECT_DIR}/build.plist ] && echo "Found build.plist" || cretePlist
users=$(/usr/libexec/PlistBuddy -c "Print users" "${PROJECT_DIR}/build.plist")
mybuild=$(/usr/libexec/PlistBuddy -c "Print $currentUser" "${PROJECT_DIR}/build.plist")
alreadyIn=0
if [[ $users == *"$currentUser"* ]]
then
alreadyIn=1
fi
if [ ${alreadyIn} -eq 0 ];
then
users="$users|$currentUser"
build=1
/usr/libexec/PlistBuddy -c "Set :users $users" "${PROJECT_DIR}/build.plist"
/usr/libexec/PlistBuddy -c "Add :$currentUser string $build" "${PROJECT_DIR}/build.plist"
else
mybuild=$(($mybuild + 1))
/usr/libexec/PlistBuddy -c "Set :$currentUser $mybuild" "${PROJECT_DIR}/build.plist"
fi
IFS='|' read -ra ADDR <<< "$users"
totalBuild=0
for i in "${ADDR[@]}"; do
echo "$i"
memberbuild=$(/usr/libexec/PlistBuddy -c "Print $i" "${PROJECT_DIR}/build.plist")
totalBuild=$(($totalBuild + $memberbuild))
done
echo $totalBuild
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $totalBuild" "${PROJECT_DIR}/${INFOPLIST_FILE}"
详细用法
1. Select: your Target in Xcode
2. Select: Build Phases Tab
3. Select: Add Build Phase -> Add Run Script
4. Paste code below in to new "Run Script" section
5. Drag the "Run Script" below "Link Binaries With Libraries"
6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)
注意事项 点我