问题描述
我可以连接到我的蓝牙设备,当我想断开连接时,大约需要 30 秒才能断开连接,并在几秒钟内断开连接并在后台自动重新连接到设备我不希望这种情况发生,怎么办我从字面上断开它? 我处理服务和设备并将其拉为空,但这不起作用
这是断开连接方法:
public bool disConnect()
{
try
{
IsScannerActiwe = false;
Buttonpressed = false;
IsConnected = false;
if (currentSelectedGattCharacteristic != null && currentSelectedService != null)
{
currentSelectedGattCharacteristic.Service?.dispose();
currentSelectedService?.dispose();
currentSelectedGattCharacteristic = null;
currentSelectedService = null;
if (bluetoothLeDevice != null)
{
bluetoothLeDevice.dispose();
bluetoothLeDevice = null;
return true;
}
}
}
catch (System.Exception ex)
{
Trace.WriteLine("Exception Handled -> disConnect: " + ex);
}
return false;
}
我处理设备和服务并将其拉为空,该函数返回true但它不会断开连接并且它为空几秒钟并且服务继续在后台自动运行
public async Task<bool> ClearBluetoothLEDevice()
{
if (IsConnected)
{
IsScannerActiwe = false;
Buttonpressed = false;
IsConnected = false;
// Need to clear the CCCD from the remote device so we stop receiving notifications
var result = await currentSelectedGattCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.None);
if (result != GattCommunicationStatus.Success)
{
return false;
}
else
{
if (currentSelectedGattCharacteristic != null)
{
currentSelectedGattCharacteristic.ValueChanged -= CurrentSelectedGattCharacteristic_ValueChanged;
IsConnected = false;
currentSelectedService.dispose();
currentSelectedGattCharacteristic.Service.dispose();
currentSelectedService?.dispose(); //added code
currentSelectedService = null; //added code
bluetoothLeDevice?.dispose();
bluetoothLeDevice = null;
currentSelectedGattCharacteristic = null;
return true;
}
}
}
return false;
}
我确实无法与设备断开连接
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)