iOS 测试 搭建 IOS 应用测试分发平台

snake · 2016年10月19日 · 最后由 说好不哭 回复于 2018年06月21日 · 2798 次阅读
本帖已被设为精华帖!

苹果有太多限制,在测试中拿到包不是易事。
目前流行的有如下几种:

1.使用 iTunes 将 iPa 同步到手机中;

2.使用 itms-services 协议进行下载分发;

3.使用第三方工具进行下载分发,如:蒲公英,fir…

现在就以 2 来说说如何自己来实现分发。

流程如下:

用 Xcode 打包 IPA 版本
搭建本地 Web 服务器
开启 HTTPS
编写好对应的.plist 文件
上传 ipa、.plist、ca 证书到 Web 服务器,配置好 index.html
在手机上用 Safari 打开链接,完成下载

首先是要搞定证书。
我们得解决证书的问题。可以参考iOS 证书申请和使用详解
如果搞不定,可以找开发帮忙。
把生成的证书放到 server 上。

用 flask 搭建 web service, 比较简单。
将证书放到 upload 中,添上如下代码,可以上传下载证书了。

@app.route('/upload', methods=['POST'])
def upload():
  uploaded_files = request.files.getlist("file[]")
  filenames = []
  for file in uploaded_files:
    if file and allowed_file(file.filename):
      filename = secure_filename(file.filename)
           file.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
      filenames.append(filename)
  return render_template('upload.html', filenames=filenames)

@app.route('/down_loads')
def down_loads():
    if request.method=="GET":
        if os.listdir(os.path.join('uploads')):
            files = os.listdir(os.path.join('uploads'))
            return render_template('down_loads.html',files=files)
        abort(404)

编写 plist 文件
原理是通过 Safari 解析链接中的” itms-services://“来实现的。
链接指向 plist,plist 指向 IPA。
例如:

<a title="iPhone" href="itms-services://?action=download-manifest&url=https://192.168.**.***/install.plist">Download</a>

Safari 会去读取 install.plist 中的信息,如:iOS 应用的名称、版本、安装地址等.(这些信息,打包的时候就知道,如果不知道,可以把 ipa 解压,从解压的 info.plist 里面去获取,填到自己创建的 install.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://192.168.**.***/test.ipa</string>
                </dict>
            </array>
            <key>metadata</key>
            <dict>
                <key>bundle-identifier</key>
                <string>必须和bundleidentifier一样</string>
                <key>bundle-version</key>
                <string>版本号</string>
                <key>kind</key>
                <string>software</string>
                <key>releaseNotes</key>
                <string>(可以随意填)</string>
                <key>title</key>
                <string>App名称</string>
            </dict>
        </dict>
    </array>
</dict>
</plist>

添加配置信息
我们把刚刚建好的 plist 文件 (这里取名为 install.plist)、ipa 包、ca 证书放到 Web 服务器的文件目录下,然后修改 index.html 中的内容。
(index.html 内容):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>应用名字</title>
</head>
<body>
<h1 style="font-size:40pt">iOS应用OTA安装<h1/>
<h1 style="font-size:40pt">
<a title="iPhone" href="itms-services://?action=download-manifest&url=https://192.168.**.***/install.plist">Iphone Download</a>
<h1/>
<a title="iPhone" href="https://192.168.**.***/ca.crt">ssl 证书安装</a>
<h1/>
</body>
</html>

我们用 iphone 打开浏览器,输入本地服务器的地址,然后再点击 Download,哈哈,是不是已经弹出对话框询问需要安装了??
Oops, 弹出的框是"Cannot connect to ***"
怎么办? 服务器没有配置 https.
我们用 openssl 来生成

openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout ***.key -out ***.crt

代码中添加:

from flask import Flask
from OpenSSL import SSL

import os

context = SSL.Context(SSL.SSLv23_METHOD)
cer = os.path.join(os.path.dirname(__file__), 'resources/***.crt')
key = os.path.join(os.path.dirname(__file__), 'resources/***.key')

if __name__ == '__main__':
    context = (cer, key)
    app.run( host='0.0.0.0', port=5000, debug = True, ssl_context=context)

解决了 SSL 问题,重新启动服务,就可以下载了。
然后扩展一下 web service 功能 (如二维码),做美观一下。

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 13 条回复 时间 点赞

very good! 一般用第一种方式

通过 safra 直接安装 ipa?是否需要手机 id 添加信任。

#2 楼 @pacerron 第一步就是解决你这个问题。

楼主,测试小白想问一下三种方式都是怎么实现的,有没有自动安装的方案?

实用. 我们公司用的第二种.

我来补充一种 Apple 官方支持,实际应用中比较少使用的的方案:TestFlight Beta Testing

思寒_seveniruby 将本帖设为了精华贴 10月20日 22:30

加精理由: 方法实用. 详细解释了 iOS 的包发布机制. 能很好的辅助 CI 流程

这个 plist 文件很坑,必须得放到 https 服务器,并且用本地加密的 SSL 还不行,我们直接放到七牛上了, 不过里面包下载地址就是一般 http 没啥问题

ideviceinstaller 也可以的

ios-ipa-server 挺好用的

是不是初次安装依旧要两步,第一步安装 SSL,第二部安装包,然后再信任?

我用 Tomcat 搭建,用 https 连接,出现 Cannot connect to ,这个有解决办法么

我们公司用的 TestFlight,挺好用的啊

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册