這篇文章純給自己留個備份,所以對AdHoc證書內(nèi)部分發(fā)和對iOS客戶端開發(fā)不了解的請直接無視。
一般在iOS游戲或應(yīng)用開發(fā)過程中,正式發(fā)布到App Store之前,都需要內(nèi)部的測試,客戶端的安裝是個不大不小的問題。蘋果提供了AdHoc的證書(普通版可以裝100臺設(shè)備,企業(yè)版無限),登記設(shè)備號的即可通過iTunes或者無線網(wǎng)絡(luò)安裝使用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/
之前有用過一款產(chǎn)品叫HockeyApp(http://hockeyapp.net/),幫助實現(xiàn)內(nèi)部的分發(fā)和安裝,支持在線安裝、檢測更新,非常方便,簡單分析了一下其原理:
1. 服務(wù)端提供API供客戶端獲取最近版本信息,參考如下:
[
{
"timestamp": 1349965666,
"shortversion": "4.2.1",
"mandatory": false,
"appsize": 115812817,
"title": "Metal Nation",
"version": "4.2.1.12101102",
"notes": "修復(fù)BUG"
},
{
"timestamp": 1349788437,
"shortversion": "4.2.0",
"mandatory": false,
"appsize": 115866480,
"title": "Metal Nation",
"version": "4.2.0.12100902",
"notes": "修復(fù)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>新版本更新主要內(nèi)容:建造建筑變更為分階層進(jìn)行</p>"
},
{
"timestamp": 1345717028,
"shortversion": "3.9.4",
"mandatory": false,
"appsize": 90793414,
"title": "Metal Nation",
"version": "3.9.4.12082301",
"notes": "<p>3.9.4更新內(nèi)容細(xì)節(jié)</p>"
},
{
"timestamp": 1345115309,
"shortversion": "3.9.3",
"mandatory": false,
"appsize": 69261482,
"title": "Metal Nation",
"version": "3.9.3.12081601",
"notes": "<p>本次更新主要內(nèi)容</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>主要改進(jìn)的數(shù)值</p>"
},
{
"timestamp": 1343992275,
"shortversion": "3.9.1",
"mandatory": false,
"appsize": 66622883,
"title": "Metal Nation",
"version": "3.9.1.12080302",
"notes": "<p>本次更新主要內(nèi)容</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. 客戶端根據(jù)版本列表判斷是不是最新版本,和是不是要強(qiáng)制更新,如果需要更新,可以類似與HockeyAPP內(nèi)嵌一個網(wǎng)頁顯示版本信息,點擊更新按鈕后,訪問服務(wù)端的下載更新包的API。
網(wǎng)頁更新鏈接代碼如下:
<a href="itms-services://?action=download-manifest&url=https://sdk.hockeyapp.net/api/2/apps/565b9262a3913bb1123c71ba6575e07b?format=plist&udid=d2134514a9c016fbd016a0815f1b3f41d9f38c82">Tap Here to Update</a>
3. 服務(wù)端提供下載更新包的API,傳入用戶設(shè)備號和請求的版本號參數(shù),返回一個manifest.plist文件,本質(zhì)是一個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對應(yīng)的Url為ipa文件下載地址,其中display-image對應(yīng)的Url為App的圖標(biāo)圖片URL
5. 后臺管理中,需要增加頁面讓用戶可以上傳最新的ipa文件和輸入版本更新信息,其中ipa文件的解析邏輯如下:
- 將ipa文件作為zip文件解壓縮
- 解壓后,讀取根目錄下的Info.plist文件,是一個XML格式文件
- 讀取CFBundleShortVersionString節(jié)點,或得版本號簡寫
- 讀取CFBundleVersion獲取版本號
- 讀取CFBundleIdentifier獲取唯一編號
- 讀取CFBundleDisplayName獲取名稱
- 保存這些信息到數(shù)據(jù)庫中,在生成manifest.plist的API中用以顯示相應(yīng)數(shù)據(jù)。
基本上就這樣。