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>

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