【问题标题】:Getting unique device ID in VS2012 Windows 8 Store Apps在 VS2012 Windows 8 商店应用程序中获取唯一的设备 ID
【发布时间】:2013-07-05 12:08:45
【问题描述】:

我是 Windows 8 应用商店应用的新手,需要在我的一个 XAML 项目中获取设备 ID。并且这个设备 ID 应该是唯一的。我搜索了互联网,发现了两种不同的方式。

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);
} 

C#代码中的第二种方式,

var easClientDeviceInformation = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation()
GUID deviceId = easClientDeviceInformation.Id;

第一个以位格式给出,而第二个给出 GUID。我不知道哪个是正确的。

我提到了这个blog

还有 MSDN link

谁能指导我哪些可以用作设备ID?

【问题讨论】:

标签: c# xaml windows-8 windows-store-apps windows-8.1


【解决方案1】:

我也有同样的困惑,但最终使用了HardwareIdentification.GetPackageSpecificToken。 因为我没有找到关于EasClientDeviceInformation.ID 唯一性的信息

但是,您不能按原样使用HardwareIdentification.GetPackageSpecificToken 返回的ID,因为它依赖于许多硬件组件。如果其中任何一个发生了变化,就会返回一个不同的id。

this link 有更多信息。

【讨论】:

    【解决方案2】:

    在 VS2013 中,微软在上传从 Microsoft Push Notification Server (MPNS) 检索到的频道 URI 以实现 Push Notification 时,使用以下方法检索当前设备的唯一“安装 id”或“设备 id”:

    var token = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
    string installationId = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(token.Id);
    

    【讨论】:

      猜你喜欢
      • 2021-08-27
      • 1970-01-01
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-30
      相关资源
      最近更新 更多