Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows 10 UAP确定设备是否为物联网(如树莓Pi 2)_C#_Win Universal App_Windows 10 Iot Core - Fatal编程技术网

C# Windows 10 UAP确定设备是否为物联网(如树莓Pi 2)

C# Windows 10 UAP确定设备是否为物联网(如树莓Pi 2),c#,win-universal-app,windows-10-iot-core,C#,Win Universal App,Windows 10 Iot Core,我想知道如何确定该设备是否属于物联网系列,在我的例子中是树莓Pi 2,但我不需要知道它是否特别是树莓,只是物联网设备 我尝试了以下代码: //if(ApiInformation.IsApiContractPresent("DevicesLowLevelContract ", 1)) if (ApiInformation.IsTypePresent("Windows.Devices.Gpio")) { this.InitializeSensor(); return; } 这两个在

我想知道如何确定该设备是否属于物联网系列,在我的例子中是树莓Pi 2,但我不需要知道它是否特别是树莓,只是物联网设备

我尝试了以下代码:

//if(ApiInformation.IsApiContractPresent("DevicesLowLevelContract ", 1))
if (ApiInformation.IsTypePresent("Windows.Devices.Gpio"))
{
    this.InitializeSensor();
    return;
}

这两个在我的笔记本上都不会是真的,但在我的Rasbperry Pi上也不会是真的。有人有想法或知道如何正确处理吗?

我希望有这样的想法

Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily

是您正在寻找的-在您的情况下,它应该返回类似于
“Windows.IoT”
的内容,因为当我在桌面上的universal app中检查它时,它是
“Windows.desktop”
,而在使用Windows 10 Mobile(预览)的手机上,它是
“Windows.Mobile”

使用ApiInformation.IsTypePresent您正在查找的类型不是命名空间。“Windows.Devices.Gpio”是一个命名空间。尝试将该方法改为“Windows.Devices.Gpio.GpioController”

我建议在这里使用typeof关键字,以避免使用字符串。像这样:

ApiInformation.IsTypePresent(typeof(Windows.Devices.Gpio.GpioController).ToString());

我正在为同样的问题挣扎,请参见:


不幸的是,
IsTypePresent
对于
GpioController
类,桌面上也会返回
true

上面答案中的DeviceFamily字符串是最好的检测方法