在Windows Phone 8.1中,您可以使用HardwareIdentification获取设备ID,尽管文档称其适用于桌面应用程序,但它并不存在于UWP应用程序中。
有什么替代方案或方法可以获取UWP的硬件ID?
将应用程序从 Windows (Phone) 8(.1)
迁移到 Windows Universal Platform
时,您遇到了常见的问题。
您看不到 HardwareIdentification
的原因很简单:您没有引用所需的资源!
您只看到 AnalyticsInfo
和 AnalyticsVersionInfo
。这是因为它们是文档页面 (https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.profile.analyticsinfo.aspx) 中的 Universal Device Family 的一部分,在页面底部有说明。
然而,HardwareIdentification
不是 Universal Device Family 的一部分,它是 Desktop
和 Mobile
家族的一部分,正如 Adriano 在他的评论中已经指出的那样。
之后,请确保在调用之前检查类型是否存在:
if (Windows.Foundation.Metadata.ApiInformation
.IsTypePresent("Windows.System.Profile.HardwareIdentification"))