iOS自动打包方案

创建.sh脚本,将下面内容负责进去改下参数

脚本绝对路径

sctipt_path=$(cd `dirname $0`; pwd)
#project_path=$(cd `dirname $0`; pwd)

#工程路径:../意思是上一级目录,为了避免将脚本放到工程的根目录中导致污染

project_path=${sctipt_path}/../baoYinNew
work_type="workspace" # 有效值 project / workspace (cocoapods项目)
target_name="工程名.xcworkspace" # 有效值 ****.xcodeproj / ****.xcworkspace (cocoapods项目)

#工程名 将XXX替换成自己的工程名
project_name=XXX

#scheme名 将XXX替换成自己的sheme名
scheme_name=XXX

#打包模式 Debug/Release
development_mode=Debug

#plist文件所在路径
exportOptionsPlistPath=${sctipt_path}/exportTest.plist

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

out_sub_path=`date "+%Y-%m-%d-%H-%M-%S"`
out_base_path="xcode_build_ipa_dis"

if [ $number == 1 ];then
development_mode=Release
exportOptionsPlistPath=${sctipt_path}/exportAppstore.plist

out_sub_path=`date "+%Y-%m-%d-%H-%M-%S"`
out_base_path="App Store"

else
development_mode=Debug
exportOptionsPlistPath=${sctipt_path}/exportTest.plist
fi

#导出.ipa文件所在路径
exportIpaPath="/Users/zhaojing/BaoyinGit/打包集合"/${out_base_path}/${out_sub_path}
#mkdir命令用来创建目录,-p或--parents 若所要建立目录的上层目录目前尚未建立,则会一并建立上层目录;
mkdir -p ${exportIpaPath}

#build文件夹路径
#build_path=${project_path}/build
build_path="/Users/zhaojing/BaoyinGit/打包集合"/${out_base_path}/${out_sub_path}
#exportIpaPath=${project_path}/IPADir/${development_mode}


echo '///-----------'
echo '/// 正在清理工程'
echo '///-----------'
#xcodebuild \
#clean -configuration ${development_mode} -quiet  || exit

xcodebuild -$work_type ${project_path}/$target_name -scheme $scheme_name -configuration Release -sdk iphoneos clean

echo '///--------'
echo '/// 清理完成'
echo '///--------'
echo ''

echo '///-----------'
echo '/// 正在编译工程:'${development_mode}
echo '///-----------'
xcodebuild \
archive -workspace ${project_path}/${project_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${development_mode} \
-archivePath ${build_path}/${project_name}.xcarchive  -quiet  || exit

echo '///--------'
echo '/// 编译完成'
echo '///--------'
echo ''

echo '///----------'
echo '/// 开始ipa打包'
echo '///----------'
xcodebuild -exportArchive -archivePath ${build_path}/${project_name}.xcarchive \
-configuration ${development_mode} \
-exportPath ${exportIpaPath} \
-exportOptionsPlist ${exportOptionsPlistPath} \
-quiet || exit

if [ -e $exportIpaPath/$scheme_name.ipa ]; then
echo '///----------'
echo '/// ipa包已导出'
echo '///----------'
open $exportIpaPath
else
echo '///-------------'
echo '/// ipa包导出失败 '
echo '///-------------'
fi
echo '///------------'
echo '/// 打包ipa完成  '
echo '///-----------='
echo ''

echo '///-------------'
echo '/// 开始发布ipa包 '
echo '///-------------'

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
else
创建个.sh脚本,里面
#上传到Fir
# 将XXX替换成自己的Fir平台的token
#fir login -T XXX
#fir publish $exportIpaPath/$scheme_name.ipa

api_token=XXX

fir p ${exportIpaPath}/$scheme_name.ipa -T $api_token -c 联合贷款和消息推送测试版本


fi

exit 0

你可能感兴趣的:(iOS自动打包方案)