我写了一个宣传GATT服务的UWP应用程序。我想知道如何断开连接到我的GATT服务的客户端?
我可以使用DeviceInformation
类找到已连接的设备,但调用Dispose
和Session
对象的BluetoothLEDevice
方法无效。
string filter = BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected);
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(filter);
foreach (DeviceInformation d in devices)
{
BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(d.Id);
var gattServices = await device.GetGattServicesAsync();
foreach (var service in gattServices.Services)
{
if (service.Session.SessionStatus == GattSessionStatus.Active)
service.Session.Dispose();
service.Dispose();
}
device.Dispose();
}
还有其他方法断开客户端设备的蓝牙连接吗?