Safari瀏覽器獲取iPhone UDID

通過蘋果Safari瀏覽器獲取iPhone UDID步驟詳解:

一、獲得UDID通過移動Safari概述:

蘋果公司允許開發者通過IOS設備和Web服務器之間的某個操作,來獲得IOS設備的UDID(包括其他的一些參數)。這裏的一個概述:

1、在你的Web服務器上創建一個.mobileconfig的XML格式的描述文件;

2、用戶在所有操作之前必須通過某個點擊操作完成.mobileconfig描述文件的安裝;

3、服務器需要的數據,比如:UDID,需要在.mobileconfig描述文件中配置好,以及服務器接收數據的URL地址;

4、當用戶設備完成數據的手機後,返回一個“謝謝”的提示給客戶端用戶;


二、.mobileconfig描述文件內容及注意:

在這篇文章中,我專注於獲得標識符。你可以做很多事情,但這裏是一個獲得UDID示例配置。下面是一個.mobileconfig文件 的例子:

<?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://yourwebsite.com/retrieve.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>yourwebsite.com</string>
        <key>PayloadDisplayName</key>
        <string>Profile Service</string>
        <key>PayloadVersion</key>
        <integer>1</integer>
        <key>PayloadUUID</key>
        <string>9CF421B3-9853-4454-BC8A-982CBD3C907C</string>
        <key>PayloadIdentifier</key>
        <string>com.yourwebsite.profile-service</string>
        <key>PayloadDescription</key>
        <string>This temporary profile will be used to find and display your current device's UDID.</string>
        <key>PayloadType</key>
        <string>Profile Service</string>
    </dict>
</plist>

你需要填寫你自己的URL和PayloadUUID。該PayloadUUID並不一定是產生的一種特殊方式,確保它是您的應用程序的獨特。

注意:mobileconfig下載時設置文件內容類型Content Type爲:application/x-apple-aspen-config。


三、用戶端安裝.mobileconfig描述文件:

下面的界面就是用戶通過瀏覽器點擊開始安裝時的界面,用戶點擊“Install”開始安裝,下面的mobileconfig文件是沒有簽名的,所以會顯示“Unsigned”紅色提示;如需簽名,

可參見:Sign the mobileconfig file with Java



四、接收客戶端返回數據:

在你的Web服務器端,必須設置一個接收返回參數的URL,這個URL是在mobileconfig文件中的URL參數中配置的,設備返回的是XML格式流文件,如果你的Web程序是Java寫的話,可以參見下面的方法將流文件轉化成字符串:

  /**
    * 將inputStream轉化成爲String
    * @param is
    * @return
    * @throws IOException
  */
 public static String inputStream2String(InputStream is) throws IOException{ 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    int i = -1; 
    while((i=is.read())!=-1){ 
           baos.write(i); 
    } 
    return baos.toString(); 
 } 


下面的數據就是返回數據的一個例子:

<!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>12 123456 123456 7</string>
    <key>PRODUCT</key>
    <string>iPhone4,1</string>
    <key>UDID</key>
    <string>b59769e6c28b73b1195009d4b21cXXXXXXXXXXXX</string>
    <key>VERSION</key>
    <string>9B206</string>
  </dict>
</plist>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章