【发布时间】:2017-12-24 18:36:49
【问题描述】:
我正在 WPF 应用程序中使用以下代码进行配对测试,但它总是以 Failed 状态失败。
要使用 BluetoothLe 库,我刚刚添加了参考 (C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd)
if (!DeviceInformation.Pairing.IsPaired)
{
Logger.Info($"{DeviceInformation.Name} Try Pairing");
var result = await DeviceInformation.Pairing.PairAsync(DevicePairingProtectionLevel.None);
Logger.Info($"{result.Status}");
}
奇怪的是
使用相同代码的 UWP 应用可以配对。
在 UWP 和 WPF 应用程序中都可以取消配对。
不同的是,UWP 应用总是弹出系统对话框确认配对和取消配对,而 WPF 应用不显示任何对话框。
谁能帮帮我?
解决了!谢谢你。 我刚刚使用了自定义配对。
public async void Pair()
{
if (!DeviceInformation.Pairing.IsPaired)
{
Logger.Info($"{DeviceInformation.Name} Try Pairing");
DeviceInformation.Pairing.Custom.PairingRequested += CustomOnPairingRequested;
var result = await DeviceInformation.Pairing.Custom.PairAsync(
DevicePairingKinds.ConfirmOnly, DevicePairingProtectionLevel.None);
DeviceInformation.Pairing.Custom.PairingRequested -= CustomOnPairingRequested;
Logger.Info($"{result.Status}");
}
}
private void CustomOnPairingRequested(
DeviceInformationCustomPairing sender,
DevicePairingRequestedEventArgs args)
{
Logger.Info("Test");
args.Accept();
}
【问题讨论】:
标签: c# wpf uwp bluetooth-lowenergy