簽名原理
使用了蘋果提供給開發者的Ad-Hoc分發通道,把安裝設備當做開發設備進行分發。
優勢:
直接分發,安裝即可運行
穩定,不會有證書吊銷導致的風險
缺點:
單開發者賬號的iPhone設備數量只有100個
整體架構
- 設備安裝描述文件后,會向服務器發送設備的UDID。
- 服務器收到UDID后,將UDID注冊到某個開發者賬號下。
- 再生成簽名用的描述文件,給IPA簽名。
- 然后iPA傳Server,使用itms-services方式讓用戶下載。
技術實現
一、使用配置文件獲取UDID
- 在你的Web服務器上創建一個.mobileconfig的描述文件;
- 用戶點擊完成.mobileconfig描述文件的安裝;
- 服務器需要的數據,比如:UDID,需要在.mobileconfig描述文件中配置好,以及服務器接收數據的URL地址;
- 當用戶設備安裝描述文件后,設備會回調你設置的URL
注:.mobileconfig的demo如下:<?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>PayloadContent</key> <dict> <key>URL</key> <string>http://192.168.1.40/data/receive.php</string> <!--接收數據的接口地址--> <key>DeviceAttributes</key> <array> <string>UDID</string> <string>IMEI</string> <string>ICCID</string> <string>VERSION</string> <string>PRODUCT</string> </array> </dict> <key>PayloadOrganization</key> <string>com.sssss.orgName</string> <!--組織名稱--> <key>PayloadDisplayName</key> <string>獲取設備UDID</string> <!--安裝時顯示的標題--> <key>PayloadVersion</key> <integer>1</integer> <key>PayloadUUID</key> <string>3C4DC7D2-E475-3375-489C-0BB8D737A653</string> <!--隨機填寫的字符串--> <key>PayloadIdentifier</key> <string>dev.skyfox.profile-service</string> <key>PayloadDescription</key> <string>獲取設備UDID</string> <!--描述--> <key>PayloadType</key> <string>Profile Service</string> </dict> </plist>
注意:mobileconfig下載時設置文件內容類型Content Type為:application/x-apple-aspen-config
HTTPS服務器上的文件
當訪問mobileconfig文件不能直接下載時,可能就需要設置mime content type了,application/x-apple-aspen-config,
設置content type大體上兩種方法
.htaccess增加如下配置
<IfModule mod_mime.c> AddType application/x-apple-aspen-config .mobileconfig </IfModule>
php等動態語言直接設置
//讀取文件流為$mobileconfig
header('Content-type: application/x-apple-aspen-config; chatset=utf-8');
header('Content-Disposition: attachment; filename="test.mobileconfig"');
echo $mobileconfig;
服務器接收返回數據並顯示
設置好mobileconfig文件中的URL,並且下載安裝mobileconfig之后,iOS設備會POST XML數據流給你的mobileconfig文件,PayloadContent節點中設置的URL。以下是返回數據的格式
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>IMEI</key> <string>*********</string> <key>PRODUCT</key> <string>iPhone7,1</string> <key>UDID</key> <string>*************</string> <key>VERSION</key> <string>15B206</string> </dict> </plist>
receive.php
<?php $data = file_get_contents('php://input'); //這里可以進行xml解析 header('HTTP/1.1 301 Moved Permanently'); //這里一定要301跳轉,否則設備安裝會提示"無效的描述文件" header("Location: http://192.168.1.40/udid.php?".$params); ?>
index.php
<?php $UDID = $_GET['UDID'] ? $_GET['UDID'] : $_POST['UDID']; ?> UDID:<input style="width:300px;" name="" value="<?php echo $UDID;?>" />
值得注意的是重定向一定要使用301重定向,有些重定向默認是302重定向,這樣就會導致安裝失敗,設備安裝會提示”無效的描述文件
Apple Developer Center 自動化工具
接下來的就是在獲取到用戶的UDID之后,注冊新的開發者設備+更新Provisioning Profile。 這里需要借助開源工具:Spaceship
添加設備命令:
Spaceship::Portal.device.create!(name: "Private iPhone 6", udid: "32123898...")
下載描述文件:
profiles_appstore_adhoc = Spaceship::Portal.provisioning_profile.ad_hoc.all File.write("NFname.mobileprovision", profile.download)
自動簽名
推薦使用 Sigh 這個框架(只能mac環境), 還可以使用開心命令行簽名工具,利用p12證書來實現在linux服務器上也能重簽名。
分發已簽名的應用
可參照部署企業包的方式