FlutterBleLib icon indicating copy to clipboard operation
FlutterBleLib copied to clipboard

Disconnecting from BLE device on iOS does not work properly

Open kamil-chmiel opened this issue 5 years ago • 1 comments

I'm connecting to BLE device to read some characteristics and listen for notifications. When I'm done I would like to disconnect the device. When I call disconnectOrCancelConnection() it says device was disconnected, but I can see on my BLE device that it is still connected. Also when I look into iOS system settings I can see that my device is still connected.

Am I missing something or this method doesn't work as it should?

I found some info, but I'm not sure if this is the case: "...canceling a local connection does not guarantee that the underlying physical link is immediately disconnected. From your app’s perspective, however, the peripheral is considered disconnected, and the central manager object calls the centralManager:didDisconnectPeripheral:error: method of its delegate object."

Source: https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518952-cancelperipheralconnection

kamil-chmiel avatar Mar 29 '21 11:03 kamil-chmiel

Can you try the following sequence?

  1. setup connection observer and log the status
  2. connect
  3. read the characteristic
  4. disconnect
  5. try to read the characteristic

(await all awaitable operations)

When you disconnect you should get a disconnected state and the second read should with with device disconnected or device not connected error (code 201 or 205).

mikolak avatar Apr 07 '21 16:04 mikolak