[英]Getting unique device ID in VS2012 Windows 8 Store Apps
I am new to Windows 8 Store Apps, and need to fetch device ID in one of my XAML project. 我是Windows 8 Store Apps的新手,需要在我的XAML项目之一中获取设备ID。 And this device ID should be unique.
并且该设备ID应该是唯一的。 I searched the internet and came across 2 different ways.
我搜索了互联网,发现了两种不同的方式。
First way in C# code, 用C#代码的第一种方式,
private string GetHardwareId()
{
var token = HardwareIdentification.GetPackageSpecificToken(null);
var hardwareId = token.Id;
var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
byte[] bytes = new byte[hardwareId.Length];
dataReader.ReadBytes(bytes);
return BitConverter.ToString(bytes);
}
Second way in C# code, C#代码的第二种方式,
var easClientDeviceInformation = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation()
GUID deviceId = easClientDeviceInformation.Id;
The first one gives in bits format whereas second one gives GUID. 第一个给出位格式,而第二个给出GUID。 I am not getting any idea that which is correct one.
我不知道哪个是正确的。
And MSDN link too. 也和MSDN 链接 。
Can any one guide me regarding which can be used as Device ID? 谁能指导我将哪个用作设备ID?
I had same confusion, but finally used HardwareIdentification.GetPackageSpecificToken
. 我有同样的困惑,但最终使用了
HardwareIdentification.GetPackageSpecificToken
。 Because I find no information about uniqueness of EasClientDeviceInformation.ID
因为我找不到有关
EasClientDeviceInformation.ID
唯一性的EasClientDeviceInformation.ID
However, you can't use ID
returned by HardwareIdentification.GetPackageSpecificToken
as it is, because it depends upon many hardware components. 但是,您不能原样使用
HardwareIdentification.GetPackageSpecificToken
返回的ID
,因为它取决于许多硬件组件。 And if any one of them changed, a different id will be returned. 并且如果其中任何一个更改,将返回一个不同的ID。
In VS2013, Microsoft uses the following method to retrieve the unique "installation id" or "device id" for the current device when uploading a channel URI retrieved from the Microsoft Push Notification Server (MPNS) to implement Push Notification: 在VS2013中,当上载从Microsoft Push Notification Server(MPNS)检索来实现Push Notification的通道URI时,Microsoft使用以下方法为当前设备检索唯一的“安装ID”或“设备ID”:
var token = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
string installationId = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(token.Id);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.