首页 > 代码库 > iOS客户端的在线安装和更新—针对ADHoc证书
iOS客户端的在线安装和更新—针对ADHoc证书
这篇文章纯给自己留个备份,所以对AdHoc证书内部分发和对iOS客户端开发不了解的请直接无视。
一般在iOS游戏或应用开发过程中,正式发布到App Store之前,都需要内部的测试,客户端的安装是个不大不小的问题。苹果提供了AdHoc的证书(普通版可以装100台设备,企业版无限),登记设备号 的即可通过iTunes或者无线网络安装使用AdHoc证书的App。具体不多赘述。
参考资料:
http://www.alexcurylo.com/blog/2010/08/27/wireless-ad-hoc-distribution/
http://www.hanchorllc.com/2010/08/24/introducing-ios-beta-builder/
之前有用过一款产品叫HockeyApp(http://hockeyapp.net/),帮助实现内部的分发和安装,支持在线安装、检测更新,非常方便,简单分析了一下其原理:
1. 服务端提供API供客户端获取最近版本信息,参考如下:
https://sdk.hockeyapp.net/api/2/apps/565b9262a3913bb1123c71ba6575e07b?format=json&udid=d2134514a9c016fbd016a0815f1b3f41d9f38c82&sdk=HockeySDK&sdk_version=2.5.4b1&uuid=87dcb0e9981f34f6ad998590087fc554&app_version=4.2.0.12100902&os=iOS&os_version=6.0&device=iPhone3%2C1&lang=zh-Hans&first_start_at=10%2F09%2F2012&usage_time=27300 |
[
{
"timestamp": 1349965666,
"shortversion": "4.2.1",
"mandatory": false,
"appsize": 115812817,
"title": "Metal Nation",
"version": "4.2.1.12101102",
"notes": "修复BUG"
},
{
"timestamp": 1349788437,
"shortversion": "4.2.0",
"mandatory": false,
"appsize": 115866480,
"title": "Metal Nation",
"version": "4.2.0.12100902",
"notes": "修复BUG"
},
{
"timestamp": 1349704154,
"shortversion": "4.2.0",
"mandatory": false,
"appsize": 115866530,
"title": "Metal Nation",
"version": "4.2.0.12100801",
"notes": "<p>解决无法访问的问题。</p>"
},
{
"timestamp": 1348125250,
"shortversion": "4.1.0",
"mandatory": true,
"appsize": 133946599,
"title": "Metal Nation",
"version": "4.1.0.12092001",
"notes": "<p>新版本更新主要内容:建造建筑变更为分阶层进行</p>"
},
{
"timestamp": 1345717028,
"shortversion": "3.9.4",
"mandatory": false,
"appsize": 90793414,
"title": "Metal Nation",
"version": "3.9.4.12082301",
"notes": "<p>3.9.4更新内容细节</p>"
},
{
"timestamp": 1345115309,
"shortversion": "3.9.3",
"mandatory": false,
"appsize": 69261482,
"title": "Metal Nation",
"version": "3.9.3.12081601",
"notes": "<p>本次更新主要内容</p>"
},
{
"timestamp": 1344597742,
"shortversion": "3.9.2",
"mandatory": false,
"appsize": 67664284,
"title": "Metal Nation",
"version": "3.9.2.12081002",
"notes": "<p>PA3.9.2更新说明</p>"
},
{
"timestamp": 1344332672,
"shortversion": "3.9.1",
"mandatory": false,
"appsize": 66645470,
"title": "Metal Nation",
"version": "3.9.1.12080701",
"notes": "<p>主要改进的数值</p>"
},
{
"timestamp": 1343992275,
"shortversion": "3.9.1",
"mandatory": false,
"appsize": 66622883,
"title": "Metal Nation",
"version": "3.9.1.12080302",
"notes": "<p>本次更新主要内容</p>"
},
{
"timestamp": 1343992251,
"shortversion": "3.9.1",
"mandatory": false,
"appsize": 66622828,
"title": "Metal Nation",
"version": "3.9.1.12080301",
"notes": ""
},
{
"timestamp": 1343813073,
"shortversion": "3.9.1",
"mandatory": false,
"appsize": 66602801,
"title": "Metal Nation",
"version": "3.9.1.12080101",
"notes": ""
},
{
"timestamp": 1343727905,
"shortversion": "3.9.1",
"mandatory": false,
"appsize": 66560890,
"title": "Metal Nation",
"version": "3.9.1.12073101",
"notes": ""
}
]
2. 客户端根据版本列表判断是不是最新版本,和是不是要强制更新,如果需要更新,可以类似与HockeyAPP内嵌一个网页显示版本信息,点击更新按钮后,访问服务端的下载更新包的API。
网页更新链接代码如下:
<a href="http://www.mamicode.com/itms-services://?action=download-manifest&url=https://sdk.hockeyapp.net/api/2/apps/565b9262a3913bb1123c71ba6575e07b?format=plist&udid=d2134514a9c016fbd016a0815f1b3f41d9f38c82">Tap Here to Update</a>
3. 服务端提供下载更新包的API,传入用户设备号和请求的版本号参数,返回一个manifest.plist文件,本质是一个XML,包含更新包描述信息,参考如下:
https://sdk.hockeyapp.net/api/2/apps/565b9262a3913bb1123c71ba6575e07b?format=plist&udid=d2134514a9c016fbd016a0815f1b3f41d9f38c82
<?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://sdk.hockeyapp.net/api/2/apps/565b9262a3913bb1123c71ba6575e07b?format=ipa&udid=d2134514a9c016fbd016a0815f1b3f41d9f38c82</string>
</dict>
<dict>
<key>kind</key>
<string>display-image</string>
<key>needs-shine</key>
<false />
<key>url</key>
<string>https://sdk.hockeyapp.net/api/2/apps/565b9262a3913bb1123c71ba6575e07b?format=png&udid=d2134514a9c016fbd016a0815f1b3f41d9f38c82</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>com.idfsoft.idfCity</string>
<key>bundle-version</key>
<string>4.2.1.12101102</string>
<key>subtitle</key>
<string>4.2.1 (4.2.1.12101102)</string>
<key>title</key>
<string>Metal Nation</string>
<key>kind</key>
<string>software</string>
</dict>
</dict>
</array>
</dict>
</plist>
其中software-package对应的Url为ipa文件下载地址,其中display-image对应的Url为App的图标图片URL
5. 后台管理中,需要增加页面让用户可以上传最新的ipa文件和输入版本更新信息,其中ipa文件的解析逻辑如下:
- 将ipa文件作为zip文件解压缩
- 解压后,读取根目录下的Info.plist文件,是一个XML格式文件
- 读取CFBundleShortVersionString节点,或得版本号简写
- 读取CFBundleVersion获取版本号
- 读取CFBundleIdentifier获取唯一编号
- 读取CFBundleDisplayName获取名称
- 保存这些信息到数据库中,在生成manifest.plist的API中用以显示相应数据。
基本上就这样。