在持续集成的最后打出的ipa包需要给外部进行安装,ipa包直接下载到iphone手机上是会发现并没有办法打开安装,进行询问原生开发后得知ipa包安装需要通过苹果自带的分发机制.
本文目的是实现ipa包的安装,以下是实现步骤.
由python的flask实现分发服务.
from flask import Flask
from flask import render_template, make_response, send_file
app = Flask(__name__)
#手机访问的下载包路径
@app.route('/ipa.html')
def ipa_install():
return render_template('ipa_install.html')
#分发机制文件的路径
@app.route('/manifest.plist')
def manifest_plist():
return render_template('manifest.plist')
#分发文件内ipa包的路径
@app.route('/hello_world.ipa')
def download():
response = make_response(send_file(hello_world.ipa)) #send_file内填写ipa包路径
response.headers["Content-Disposition"] = "attachment; filename=hello_world.ipa;"
return response
if __name__ == '__main__':
#使用ssl_context目的是因为苹果ipa包下载必须使用https协议不然会报证书错误
#不知道怎么生成证书可以参考https://www.jianshu.com/p/3d743fca1fd6
app.run(ssl_context=(r'server.crt',r'server.key'))
manifest.plist文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>https://xxx.xxx.xxx/hello_world.ipa</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>填写ipa包内info.plist文件内的CFBundleIdentifier,例如:com.xxx.helloWorld</string>
<key>bundle-version</key>
<string>填写ipa包内info.plist文件内的CFBundleShortVersionString,例如:com.xxx.helloWorld1.0.0</string>
<key>kind</key>
<string>software</string>
<key>platform-identifier</key>
<string>填写适用安装的类型手机设备为:com.apple.platform.iphoneos</string>
<key>title</key>
<string>hello_world</string>
</dict>
</dict>
</array>
</dict>
</plist>
ipa_install.html文件内容
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
var url = "https://xxx.xxx.xxx/manifest.plist";
window.location = "itms-services://?action=download-manifest&url=" + url;
</script>
<p>hello</p>
</body>
</html>
之后苹果手机访问https://xxx.xxx.xxx/ipa.html就可以进行下载了