有 2 个标识符可以一起用于识别特定设备和用户。
DeviceUniqueId 和 WindowsLiveAnonymousId
第一个是设备,如前所述,在被禁止用户之后使用该设备的任何人也将被禁止。
WindowsLiveAnonymousId 对用户来说是唯一的。我在 3 个不同的设备上看到了相同的标识符,并且对于用户 LiveId 来说总是相同的。
我使用以下 2 种方法来获取这些 id 来识别排行榜的游戏玩家:
//Note: to get a result requires ID_CAP_IDENTITY_DEVICE
// to be added to the capabilities of the WMAppManifest
// this will then warn users in marketplace
public static byte[] GetDeviceUniqueId()
{
byte[] result = null;
object uniqueId;
if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId))
result = (byte[])uniqueId;
return result;
}
// NOTE: to get a result requires ID_CAP_IDENTITY_USER
// to be added to the capabilities of the WMAppManifest
// this will then warn users in marketplace
public static string GetWindowsLiveAnonymousId()
{
string result = String.Empty;
object anid;
if (UserExtendedProperties.TryGetValue("ANID", out anid))
{
if (anid != null && anid.ToString().Length >= (AnidLength + AnidOffset))
{
result = anid.ToString().Substring(AnidOffset, AnidLength);
}
}
return result;
}
它们是这样使用的:
string deviceUniqueId = String.Empty;
for (int i = 0; i < GetDeviceUniqueId().GetLength(0); i++)
{
deviceUniqueId += GetDeviceUniqueId().GetValue(i);
}
DeviceUniqueIDTextBlock.Text = deviceUniqueId;
WindowsLiveAnonymousIDTextBlock.Text = GetWindowsLiveAnonymousId().ToString(CultureInfo.InvariantCulture);
去年五月我写了一篇关于在 WP7 上获取系统信息的帖子。此代码可在此处找到:http: //www.adambenoit.com/applications/system-info-windows-phone/
希望这可以帮助。