一个UWP应用中的设备ID(阈值1)

6
在Windows Phone 8.1中,您可以使用HardwareIdentification获取设备ID,尽管文档称其适用于桌面应用程序,但它并不存在于UWP应用程序中。

Screenshot of hardware profile not existing

有什么替代方案或方法可以获取UWP的硬件ID?

如果你的目标是通用应用程序(仅限移动和桌面),那么它并不意味着它存在。这是合理的,因为HardwareIdentification并不适用于所有支持UWP的目标。 - Adriano Repetti
@AdrianoRepetti 你说得对。不过我不同意“合理”的观点——每个设备都应该有一个唯一的ID。我想不出哪个设备不能有一个唯一的ID。 - Robert MacLean
1个回答

16

将应用程序从 Windows (Phone) 8(.1) 迁移到 Windows Universal Platform 时,您遇到了常见的问题。

您看不到 HardwareIdentification 的原因很简单:您没有引用所需的资源!

您只看到 AnalyticsInfoAnalyticsVersionInfo。这是因为它们是文档页面 (https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.profile.analyticsinfo.aspx) 中的 Universal Device Family 的一部分,在页面底部有说明。

然而,HardwareIdentification 不是 Universal Device Family 的一部分,它是 DesktopMobile 家族的一部分,正如 Adriano 在他的评论中已经指出的那样。

要使信息可用,请添加对特定扩展的引用: enter image description here

之后,请确保在调用之前检查类型是否存在:

if (Windows.Foundation.Metadata.ApiInformation
    .IsTypePresent("Windows.System.Profile.HardwareIdentification"))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接