dotintent / FlutterBleLib

Bluetooth Low Energy library for Flutter with support for simulating peripherals
Apache License 2.0
530 stars 194 forks source link

Disconnecting from BLE device on iOS does not work properly #585

Open kamil-chmiel opened 3 years ago

kamil-chmiel commented 3 years ago

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

mikolak commented 3 years ago

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).