iOS史上最简单的自动打包上传工具,xcode编译完成自动进行。
2018-12-11 本文已影响13人
even_cheng
如题
由于测试环境经常需要不断地修改-打包-测试-修改...,如果使用xcode原生的打包方式费事费时,或者使用fastlane,Jenkins等自动集成工具,但是前期配置麻烦且费力,后期问题不断又不好解决,于是有了以下内容:
目的:修改一个参数即可实现自动打包上传一步搞定
开始:
NO.1 添加script phase
`
`
NO.2 添加获取你的python运行地址 (一般是/usr/bin/python)
不确定的可以终端运行命令: whereis python 获取
NO.3 拷贝以下代码到文件中
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import requests
import webbrowser
import subprocess
import shutil
# if need update package please set 1
updatePackage = 0
appFileFullPath = '/Users/Cube/Library/Developer/Xcode/DerivedData/TaoMei-cgateidmhzznixahnazxrlluggia/Build/Products/Debug-iphoneos/TaoMei.app'
PayLoadPath = '/Users/Cube/Desktop/Payload'
packBagPath = '/Users/Cube/Desktop/ProgramBag'
openUrlPath = 'https://www.pgyer.com/manager/dashboard/app/55a92912ff9d474b9bf9358a25047041'
USER_KEY = "14da2a85e3407edcfbe59c4f042f2987"
API_KEY = "2cb66731e946cc0ef507542f3ee42edc"
def uploadIPA(IPAPath):
if(IPAPath==''):
print("\n*************** NONE IPA*********************\n")
return
else:
print("\n***************BEGIN UPLOAD *********************\n")
url='http://www.pgyer.com/apiv1/app/upload'
data={
'uKey':USER_KEY,
'_api_key':API_KEY,
'installType':'2',
'password':'',
'updateDescription':""
}
files={'file':open(IPAPath,'rb')}
r=requests.post(url,data=data,files=files)
def openDownloadUrl():
os.chdir('/Users/Cube/Desktop')
subprocess.call(["rm","-rf",packBagPath])
webbrowser.open(openUrlPath,new=1,autoraise=True)
print ("\n*************** SUCCESS *********************\n")
def bulidIPA():
subprocess.call(["rm","-rf",packBagPath])
mkdir(PayLoadPath)
subprocess.call(["cp","-r",appFileFullPath,PayLoadPath])
subprocess.call(["mkdir","-p",packBagPath])
subprocess.call(["cp","-r",PayLoadPath,packBagPath])
subprocess.call(["rm","-rf",PayLoadPath])
os.chdir(packBagPath)
subprocess.call(["zip","-r","./Payload.zip","."])
print ("\n*************** PACK DONE *********************\n")
subprocess.call(["mv","payload.zip","Payload.ipa"])
subprocess.call(["rm","-rf","./Payload"])
def mkdir(PayLoadPath):
isExists = os.path.exists(PayLoadPath)
if not isExists:
os.makedirs(PayLoadPath)
print(PayLoadPath + 'BUILD DONE')
return True
else:
print (PayLoadPath + 'BUILD FALSE')
return False
if __name__ == '__main__':
if updatePackage:
bulidIPA()
uploadIPA('%s/Payload.ipa'%packBagPath)
openDownloadUrl()
else:
print ("\n*************** NO PACKAGE *********************\n")
这里请注意拷贝格式,python语法对缩进额对齐极其严格.
NO.4 去蒲公英主页创建你的APP,并获取相应的key,修改项目中的参数
end
需要打包的时候修改updatePackage
参数为1即可,连接真机编译,完成自动上传到蒲公英主页并且打开你的浏览器刷新.