看起来您无需太多工作即可获得 UDID,此答案来自此博客文章:
http://bendytree.com/tips/Getting-an-iPhone-UDID-from-Mobile-Safari
Apple 允许开发人员通过手机和您的网络服务器之间的特殊交互来获取一个人的 UDID(以及做许多其他事情)。这是一个概述:
- 他们单击指向您网站上 .mobileconfig XML 文件的链接
- 这会在他们的手机上调出他们的配置设置并为他们提供
“安装”按钮(他们必须按下)
- 电话将您请求的加密 XML 数据发送到您在
.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 注册一个文件处理程序(内容类型 application/x-apple-aspen-config)。
PayloadOrganization 和 PayloadDescription 会在用户看到配置文件时显示给他们。在我的描述中,我说了类似“按安装以继续...”之类的内容,因为他们可能会在此屏幕上感到困惑。
您不必对 .mobileconfig 进行签名,但如果您不这样做,他们会看到未签名的警告(见下文)。
接收请求的数据
QUIRK WARNING:无论出于何种原因,该过程对于您的服务器在将用户发送到您的预设 URL 时的响应方式非常特别。经过多次尝试,我相信您的接收网址必须是 .php 文件。这听起来很疯狂,但我是认真的。
PHP 是我想使用的最后一种语言,所以我选择重定向到可以更好地处理它的页面。
<?php
$data = file_get_contents('php://input');
header("Location: http://www.mysite.com/Results?data=".rawurlencode($data));
?>
QUIRK WARNING:: 我(和其他人)让它工作的唯一方法是重定向到一个目录。我尝试重定向到 .aspx 页面,但失败了。如果您不正确,则会向用户显示一条模糊的错误消息,他们将被卡住。如果您对此有更好的解释,请在下面发表评论。
您重定向到的页面是显示给用户以结束进程的页面。
在我的示例中,该页面将收到一个“数据”查询字符串参数,其中包含来自手机的 xml 响应。
<!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>