Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.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# 无头UWP蓝牙配对,无需用户pin输入_C#_Uwp_Bluetooth_Headless_Windows 10 Iot Core - Fatal编程技术网

C# 无头UWP蓝牙配对,无需用户pin输入

C# 无头UWP蓝牙配对,无需用户pin输入,c#,uwp,bluetooth,headless,windows-10-iot-core,C#,Uwp,Bluetooth,Headless,Windows 10 Iot Core,我目前正在构建一个运行在Windows10物联网核心上的无头UWP应用程序。我需要能够通过蓝牙(RFCOMM)将移动设备连接到信息亭以获取数据。我需要能够从移动设备启动配对 我已经试过了所有这些,但大部分都是在试验——特别是场景9——定制设备配对。我可以使用PIN成功配对到有头UWP应用程序,但我无法成功配对到我的无头UWP应用程序-当我尝试启动配对时,我会得到“失败”结果或“身份验证超时”结果 在没有UI的情况下,一对无头UWP应用程序如何检索pin?我可以接受UWP应用程序在每次配对尝试中都

我目前正在构建一个运行在Windows10物联网核心上的无头UWP应用程序。我需要能够通过蓝牙(RFCOMM)将移动设备连接到信息亭以获取数据。我需要能够从移动设备启动配对

我已经试过了所有这些,但大部分都是在试验——特别是场景9——定制设备配对。我可以使用PIN成功配对到有头UWP应用程序,但我无法成功配对到我的无头UWP应用程序-当我尝试启动配对时,我会得到“失败”结果或“身份验证超时”结果


在没有UI的情况下,一对无头UWP应用程序如何检索pin?我可以接受UWP应用程序在每次配对尝试中都使用硬编码pin而不是随机pin,但我不确定这是否可行?

您可以尝试使用以下代码。当有传入的配对请求时,将调用handlerUpdater

            handlerUpdated = new TypedEventHandler<DeviceWatcher, DeviceInformationUpdate>(async (watcher, deviceInfoUpdate) =>
            {
                // Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
                await MainPage.Current.UIThreadDispatcher.RunAsync(CoreDispatcherPriority.Low, async () =>
                {
                    // Find the corresponding updated DeviceInformation in the collection and pass the update object
                    // to the Update method of the existing DeviceInformation. This automatically updates the object
                    // for us.
                    foreach (BluetoothDeviceInformationDisplay deviceInfoDisp in bluetoothDeviceObservableCollection)
                    {
                        if (deviceInfoDisp.Id == deviceInfoUpdate.Id)
                        {
                            if (deviceInfoDisp.DeviceInformation.Pairing.CanPair)
                            {
                                await deviceInfoDisp.DeviceInformation.Pairing.Custom.PairAsync(DevicePairingKinds.ConfirmOnly);
                            }

                            deviceInfoDisp.Update(deviceInfoUpdate);
                            break;
                        }
                    }
                });
            });
            deviceWatcher.Updated += handlerUpdated;
handler更新=新类型deventhandler(异步(观察者,设备信息更新)=>
{
//由于集合已绑定到UI元素,因此需要在UI线程上更新集合。
等待MainPage.Current.UIThreadDispatcher.RunAsync(CoreDispatcherPriority.Low,async()=>
{
//在集合中找到相应的更新设备信息,并传递更新对象
//到现有设备信息的更新方法。这将自动更新对象
//对我们来说。
foreach(BluetoothDeviceInformation在bluetoothDeviceObservableCollection中显示设备信息)
{
if(DeviceInfo disp.Id==DeviceInfo更新.Id)
{
if(DeviceInfo Disp.DeviceInformation.Pairing.CanPair)
{
等待DeviceInfo Disp.DeviceInformation.Pairing.Custom.PairAsync(DevicePairingKinds.ConfirmOnly);
}
DeviceInfo.Update(DeviceInfo更新);
打破
}
}
});
});
deviceWatcher.Updated+=handlerUpdated;

谢谢您的回复。我已经在中更新了DeviceWatcherHelper,以包含您建议的代码。不幸的是,我仍然收到“身份验证超时”错误。你还有其他建议吗?我认为,如果有一个可以工作的无头UWP示例应用程序来演示无pin配对,对Windows 10 IoT核心社区将非常有帮助。我非常乐意提交一份,但我需要进一步的指导。