實現xcode編譯時自動修改App的版本號和構建版本號
阿新 • • 發佈:2020-12-19
技術標籤:Xcode
在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)