一. 遇到的坑
说明:xcode8.3
之后不能用PackageApplication
打包.因为8.3之后这个命令被废弃了.所以后面需要exportArchive进行打包.
二. 脚本展示
#!/bin/bash
# by allen.
SourcePath=/Users/user_name/project_name #项目的位置
TargetName=project_name #项目的名字
IPAPath=/Users/user_name/Desktop/IPA #打包后IPA文件位置
DebugMode=Debug #打包模式
echo '**************打包开始**************'
#选择打测试包还是发布包
echo "Place enter the number you want to export ? [ 1:app-store 2:ad-hoc] "
##
read number
while([[ $number != 1 ]] && [[ $number != 2 ]])
do
echo "Error! Should enter 1 or 2"
echo "Place enter the number you want to export ? [ 1:app-store 2:ad-hoc] "
read number
done
if [ $number == 1 ];
then
DebugMode=Release
DevelopExportOptionsPlist=$SourcePath/app_store.plist
else
DebugMode=Debug
DevelopExportOptionsPlist=$SourcePath/ad_hoc.plist
fi
# 读取plist
DevelopExportOptionsPlist=${DevelopExportOptionsPlist}
# clean
echo ///-----------
echo /// cleaning project
echo ///-----------
xcodebuild \
clean -configuration $DebugMode -quiet || exit
#pod install(如果项目需要pod 三方库)
pod install
# build
xcodebuild \
-scheme $TargetName \
-workspace $TargetName.xcworkspace \
-archivePath $TargetName.xcarchive \
-configuration $DebugMode−archivePathbuild/$TargetName.xcarchive \
archive
# generate IPA
xcodebuild \
-exportArchive \
-archivePath $TargetName.xcarchive \
-exportOptionsPlist $DevelopExportOptionsPlist \
-exportPath $IPAPath
#自动打开文件
if [ -e $IPAPath/$TargetName.ipa ];
then
echo ///----------
echo /// ipa包已导出
echo ///----------
open $IPAPath
else
echo ///-------------
echo /// ipa包导出失败
echo ///-------------
fi
#上传到app store
if [ $number == 1 ];
then
#验证并上传到App Store
# 将-u 后面的XXX替换成自己的AppleID的账号,-p后面的XXX替换成自己的密码
#altoolPath=/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool
#$altoolPath --validate-app -f ${exportIpaPath}/${scheme_name}.ipa -u XXX -p XXX -t ios --output-format xml
#$altoolPath --upload-app -f ${exportIpaPath}/${scheme_name}.ipa -u XXX -p XXX -t ios --output-format xml
fi
echo '**************打包完成**************'
网友评论