[iOS-Release] 自動修改構建號


參考:https://www.jianshu.com/p/2167f755c47e

關於發布蒲公英的腳本處理:

    需要登陸蒲公英,獲取api key和user key,如下:

    akey="1213467225788"
    ukey="1287311212132"
    boot_passwd="test"
    des_msg=`git log -1 --pretty=%B`
    ipa_path="HPPlay_Release_Payload.ipa"
    upload_url="http://www.pgyer.com/apiv1/app/upload"
    echo uploading $ipa_path to pgyer .....
    curl -F "file=@${ipa_path}" -F "uKey=${ukey}" -F "_api_key=${akey}" -F "updateDescription=${des_msg}" -F "password=${boot_passwd}" $upload_url

場景:ios app發版前,我們都要經過多輪測試,由於都是在手機上安裝,所以我們更加傾向於將包傳到蒲公英,從蒲公英掃描下載,這是一種很快捷的方式,但是有個缺點是,安裝好的包,如果開發不修改版本號(比如4.0.0),測試看到的永遠都是同一個版本號(比如4.0.0),根本看不出來是第幾次出包第幾次測試,我們就想要是版本號后面能加上第幾次構建就好了,比如4.0.0_1,4.0.0_2 ,這樣就很明白了。

先給大家看看效果圖:

 

 

下面介紹如何實現:

原理:找到代碼中定義版本號的地方,修改版本號增加“_遞增的數字”,如果版本不一樣的,數字又重新開始遞增。我們可以將上一次的版本和遞增數字寫入到一個記錄文件中,修改版本的部分,肯定是在編譯之前做,我的腳本如下:

echo ========ios ipa modify build times for pgyer=========
echo path=`pwd`
#info文件路徑
info_file=HPPlayTVAssistant/HPPlayTVAssistant/Info.plist
[ ! -f $info_file ] && echo $info_file not exist && exit 1
echo build command /usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' $info_file
#這里命令會得到${MARKETING_VERSION},是我們定義在其他地方的宏
build_n=`/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' $info_file |awk -F "(" '{print $2}' |awk -F ")" '{print $1}'`
echo build_n=$build_n
if [ "$build_n" == "MARKETING_VERSION" ];then #查找工程文件中這個宏對應的值
cur_ver_tmp=`grep -r MARKETING_VERSION HPPlayTVAssistant/HPPlayTVAssistant.xcodeproj/project.pbxproj |sed -n 1p`
echo cur_ver_tmp=$cur_ver_tmp
cur_ver=`echo $cur_ver_tmp |awk -F "= " '{print $2}' |awk -F ";" '{print $1}'`
else
cur_ver=$build_n
fi
echo cur_ver=$cur_ver
#查看記錄文件ios_pyger_last_build中的版本號(文件默認初始值是0_0,第一個0是版本號,第二個是構建次數)
last_version=`cat /Users/dabaozhuanyong/lebo/ios_pyger_last_build |awk -F "_" '{print $1}'`
#如果版本有變化,記錄文件再寫回初始值0_0
[ "$last_version" != "$cur_ver" ] && echo different version && echo 0_0 > /Users/dabaozhuanyong/lebo/ios_pyger_last_build
#獲取構建次數(下划線后面的字符)
last_build=`cat /Users/dabaozhuanyong/lebo/ios_pyger_last_build |awk -F "_" '{print $2}'`
#構建次數+1
new_build=`expr $last_build + 1 `
echo "$cur_ver"_"$new_build" > /Users/dabaozhuanyong/lebo/ios_pyger_last_build
new_ver_name="$cur_ver"_"$new_build"
echo new_ver_name=$new_ver_name
#修改info.plist文件中的版本號
/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString $new_ver_name" ${info_file}
echo check as follow:
/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' $info_file


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM