我正在WPF应用程序中使用下面的代码进行配对测试,但它总是以失败状态失败。DeviceInformation PairAsync在WPF中不起作用
要使用BluetoothLe库我刚添加引用(C:\ Program Files文件(x86)的\的Windows套件\ 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 App配对使用相同的代码即可。
在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();
}