#!/bin/bash
echo "==================(create ipa file...)=================="ios
cd `dirname $0`;api
#請求輸入內容 回車後繼續執行下一步
echo -n "輸入模式 回車繼續
1:app-store
2:ad-hoc
2f:hoc上傳至fir
2x:hoc上傳至蒲公英
"
read log
fir_log="$log \n \n fir auto release"
echo -e "log is $fir_log \nnow goon."xcode
#計時
SECONDS=0
rootPath=`pwd`
rootPath=${rootPath##*/}
echo "==== rootPath = $rootPath===="
#返回上一層 工程目錄
cd ..
path=`pwd`
#編譯工程
#自動獲取工程名字
name=$(find * -type d | grep ".xcworkspace$" | head -n 1)
name=${name%%.*}
echo "====name=$name==="bash
derivedDataPath="$path/createIpa/"
archivePath="$derivedDataPath/$name"
ipaPath="$derivedDataPath/ipa/$name.ipa"app
if [ -d "$derivedDataPath" ]; then
echo "========= derivedDataPath = $derivedDataPath"
else
mkdir "$derivedDataPath"
ficurl
#生成archive文件
xcodebuild archive -workspace "$name.xcworkspace" -scheme $name -configuration Release only_active_arch=no defines_module=yes -sdk "iphoneos" -archivePath "$archivePath"iphone
#這裏須要根據本身項目配置 exportOptionsPlist
#method : app-store,enterprise, development,development
#compileBitcode : BOOL
#provisioningProfiles : DIctionary com.xx.xx : nameui
if [[ $log == 1* ]]; then
exportOptionsPlist=exportAppstore.plist
ipaPath="ipa_dis"
else
ipaPath="ipa_hoc"
exportOptionsPlist=exportHoc.plist
fi
#生成ipa文件
cd $rootPath
xcodebuild -exportArchive -archivePath "$archivePath.xcarchive" -exportPath $ipaPath -exportOptionsPlist $exportOptionsPlisturl
cd $ipaPathspa
echo "===生成ipa開始上傳 time: ${SECONDS}s==="
if [[ $log == 1* ]]; then
altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
"$altoolPath" --validate-app -f "$name.ipa" -u xx@xx.com -p xxxx -t ios --output-format xml
"$altoolPath" --upload-app -f "$name.ipa" -u xx@xx.com -p xxxx -t ios --output-format xml
#-u 帳號 -p 密碼
echo "===已上傳到apptore: ${SECONDS}s==="
else
#uploadtype f: fir ; other:蒲公英
if [[ $log == 2f* ]]; then
echo "===上傳到fir==="
#上傳到fir
fir_token="xxxx"
fir publish "$name.ipa" -T $fir_token -c "$fir_log" -Q -q
echo "===已上傳到fir time: ${SECONDS}s==="
else
echo "===上傳到蒲公英==="
apiKey="xxxx"
uKey="xxxx"
#上傳到蒲公英
curl -F "file=@$name.ipa" -F "uKey=$uKey" -F "_api_key=$apiKey" https://www.pgyer.com/apiv1/app/upload
#curl -F "file=@/tmp/example.ipa" -F "uKey=b313b5e611aa062680ec33b259a2720f" -F "_api_key=4762e4caad80abc1c41629b10ee59ffe" https://qiniu-storage.pgyer.com/apiv1/app/upload
echo "===已上傳到蒲公英 time: ${SECONDS}s==="
fi
fi
#exit;
#新建 xx.command 把上面代碼粘進去, exportOptionsPlist 放在工程根目錄某個文件夾裏 #雙擊 xx.command 運行腳本 #若是沒有權限 #終端運行 sudo chmod 777 path(文件路徑)