一般项目到了测试阶段,给内部非iOS开发人员分发测试包就成了必不可少的工作。常用的打包方式是使用Xcode->Product->Archive
,但是真的是太慢了。
使用Xcode生成打包测试包并上传FTP
1.打开项目设置页面选择Build Phases
2.点左上角+
号,选择New Run Script Phase
3.新增以下指令
# Type a script or drag a script file from your workspace to insert its path.
# 文件夹名称
FILENAME="IpaBuild"
# 测试包脚本名字
BUILDNAME="ipaBuild"
# 上传FTP脚本名字
FTPNAME="ipaUpload"
# 测试包并上FTP脚本名字
BUILDWITHFTPNAME="ipaBuildAndUpload"
# 项目构建目录
PRODUCTS_PATH="${BUILT_PRODUCTS_DIR}"
# 项目目录
TARGET_APP_PATH="$PRODUCTS_PATH/${TARGET_NAME}.app"
# 打包项目名字
#APPNAME="${TARGET_NAME}"
APPNAME="appstore"
# FTP上传-项目根目录
UPLOADFILENAMEBEFORE="${SRCROOT}"
# FTP上传-包
UPLOADFILENAME="/$BUILDNAME/$APPNAME.ipa"
# FTP地址
HOST="xxx.xxx.x.xx"
# FTP账号
USERNAME="xxx"
# FTP密码
PASSWORD="xxx"
# FTP路径
HOSTFILEPATH="/xxx/xxx/xxx/"
# 每次构建都清理目录
rm -rf $FILENAME
mkdir -p $FILENAME
# 测试包脚本
cd $FILENAME
touch $BUILDNAME.command
chmod +x $BUILDNAME.command
echo "#!/bin/bash" >> $BUILDNAME.command
echo 'cd `dirname $0`;' >> $BUILDNAME.command
echo "mkdir Payload;" >> $BUILDNAME.command
echo "echo =============================打包中=============================;" >> $BUILDNAME.command
echo "${BUILT_PRODUCTS}"
echo "cp -rf $TARGET_APP_PATH Payload;" >> $BUILDNAME.command
echo "zip -r -q $APPNAME.ipa Payload;" >> $BUILDNAME.command
echo "rm -rf Payload;" >> $BUILDNAME.command
echo "echo =============================打包完成=============================;" >> $BUILDNAME.command
echo "exit;" >> $BUILDNAME.command
# 上传FTP脚本
cd $FILENAME
touch $FTPNAME.command
chmod +x $FTPNAME.command
echo "#!/usr/bin/expect -f" >> $FTPNAME.command
echo "set uploadFileNameBefore $UPLOADFILENAMEBEFORE" >> $FTPNAME.command
echo "set uploadFileName $UPLOADFILENAME" >> $FTPNAME.command
echo "set host $HOST" >> $FTPNAME.command
echo "set username $USERNAME" >> $FTPNAME.command
echo "set password $PASSWORD" >> $FTPNAME.command
echo "spawn sftp $USERNAME@$HOST" >> $FTPNAME.command
echo 'expect {
"(yes/no)?" {send "yes\r"; exp_continue}
"password:" {send "'$PASSWORD'\r"}
}' >> $FTPNAME.command
echo 'expect "sftp>"' >> $FTPNAME.command
echo 'send "cd '$HOSTFILEPATH'\r"' >> $FTPNAME.command
echo 'expect "sftp>"' >> $FTPNAME.command
echo 'send "put '$UPLOADFILENAMEBEFORE''$UPLOADFILENAME'\r"' >> $FTPNAME.command
echo 'expect "sftp>"' >> $FTPNAME.command
echo 'send "bye\r"' >> $FTPNAME.command
echo "expect eof" >> $FTPNAME.command
# 测试包并上FTP脚本
cd $FILENAME
touch $BUILDWITHFTPNAME.command
chmod +x $BUILDWITHFTPNAME.command
echo "#!/bin/bash" >> $BUILDWITHFTPNAME.command
echo 'cd `dirname $0`;' >> $BUILDWITHFTPNAME.command
echo "mkdir Payload;" >> $BUILDWITHFTPNAME.command
echo "echo =============================打包中=============================;" >> $BUILDWITHFTPNAME.command
echo "${BUILT_PRODUCTS}"
echo "cp -rf $TARGET_APP_PATH Payload;" >> $BUILDWITHFTPNAME.command
echo "zip -r -q $APPNAME.ipa Payload;" >> $BUILDWITHFTPNAME.command
echo "rm -rf Payload;" >> $BUILDWITHFTPNAME.command
echo "echo =============================打包完成=============================;" >> $BUILDWITHFTPNAME.command
echo "open $UPLOADFILENAMEBEFORE/$FILENAME/$FTPNAME.command" >> $BUILDWITHFTPNAME.command
echo "exit;" >> $BUILDWITHFTPNAME.command
效果
command + r 之后项目目录下会生成ipaBulid目录(或你自定义)
image.png生成了三个文件
- ipaBuild 单纯打测试包
- ipaUpload 单纯上传FTP
-
ipaBuildAndUpload 打测试包并上传
image.png
点击对应脚本就可以执行
注意
- 这个是打测试包的
- 不要选择模拟器运行
网友评论