前言
从事iOS最经常遇到的莫过于 测试同学过来 通知你 赶紧发个包 ~ ~ 。。然后一顿操作。作为一个有着多年iOS开发经验的程序猿,肯定不能再走寻常路,遂决定亲自写个脚本 ps: 其实是python忘的差不多了(本来也不咋的) 赶紧练练手 复习复习
相关配置
前提:mac配置python3
IDE工具:Pycharm
网络请求工具:Requests
脚本工具: Xcode
代码实现
编译并打包生成ipa文件
清理工程(command+shift+k)
def cleanProject(self):
global isWorkSpace
if isWorkSpace:
os.system(
'cd %s;xcodebuild -workspace %s.xcworkspace -scheme %s clean' % (mainPath, targetName, targetName))
else:
os.system('cd %s;xcodebuild -target %s clean' % (mainPath, targetName))
return
编译工程
def buildProject(self):
if isWorkSpace:
os.system(
"cd %s;xcodebuild -workspace %s.xcworkspace -scheme %s -configuration Release -archivePath %s/%s.xcarchive clean archive" % (
mainPath, targetName, targetName, archivePath, targetName))
else:
os.system(
"cd %s;xcodebuild -project %s.xcodeproj -scheme %s -configuration Release -archivePath %s/%s.xcarchive clean archive" % (
mainPath, targetName, targetName, archivePath, targetName))
return
导出并生成IPA文件
def cerateIPA(self):
if isDev:
os.system("cd %s; xcodebuild -exportArchive -archivePath %s/%s.xcarchive -exportPath %s/%s -exportOptionsPlist %s/DevExportOptions.plist -allowProvisioningUpdates -quiet" % (
mainPath, archivePath, targetName, archivePath, targetName, archivePath))
else:
os.system(
"cd %s; xcodebuild -exportArchive -archivePath %s/%s.xcarchive -exportPath %s/%s -exportOptionsPlist %s/DisExportOptions.plist -allowProvisioningUpdates -quiet" % (
mainPath, archivePath, targetName, archivePath, targetName, archivePath))
return
上传到蒲公英
调用蒲公英API,将ipa文件上传至自己账户
def uploadToPGY(self):
print("上传到蒲公英")
path = "%s/%s.ipa/%s.ipa" % (archivePath, targetName, targetName)
f_op = open(path, 'rb')
print(path)
print(f_op.readlines())
if os.path.exists(path):
print("找到ipa文件")
# 请求参数字典
params = {
'uKey': PGY_UKey,
'_api_key': PGY_APIKey,
'installType': PGY_INSTALL_type,
'password': PGY_PW,
'updateDescription': PGY_DES
}
response = requests.post(PGY_URL, files={
"file": open(path, 'rb')}, data=params)
else:
print("没有找到ipa文件")
上传给Itunes Connect
"""
altoolPath="/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
${altoolPath} --validate-app -f ${ipaPath} -u xxxxxx -p xxxxxx -t ios --output-format xml >>
${altoolPath} --upload-app -f ${ipaPath} -u xxxxxx -p xxxxxx -t ios --output-format xml