flutter_reactive_ble
flutter_reactive_ble copied to clipboard
Error Disconnecting To Device in iOS
Describe the bug The documentation explains that to disconnect from a device, just cancel the subscription with deviceSubscription, for example. However, on iOS, the following logs are being triggered:
Error unsubscribing from notifications: PlatformException(reactive_ble_mobile.Central.(unknown context at $104e330e4).Failure:1, The operation could not be completed.(reactive_ble_mobile.Central.(unknown context at $104e330e4).Failure erro 1.), {}, null)
To Reproduce Steps to reproduce the behavior:
- Connect to one using
connectToDevice();
- Disconnecting to device with
await deviceSubscription!.cancel();
- Observe a failure with exception:
Error unsubscribing from notifications: PlatformException(reactive_ble_mobile.Central.(unknown context at $104e330e4).Failure:1, The operation could not be completed.(reactive_ble_mobile.Central.(unknown context at $104e330e4).Failure erro 1.), {}, null)
Smartphone / tablet
- Device: iPhone XS
- OS: iOS 15.2
- Package version: 5.0.2
Peripheral device
- Does it run a custom firmware: yes
@yuriboeira11tx does this happen all the time or occasionally?
@remonh87 all the time, but only in iOS!
I'm experiencing the same issue. Error occurs on every disconnect, only on iOS devices. Using package version 5.0.2.
I am experiencing this as well.
Did some quick debugging.
On my iOS device, the disconnectFromDevice
platform method (here) gets called before the stopNotification
platform method (here)
The disconnectFromDevice
method ejects the peripheral from activePeripherals
, which causes the stopNotification
call chain to fail when trying to find the peripheral to turn off notifications.
I've run out of time to debug this for now. Hopefully someone else can run with these clues.
This is a major problem for me too, but only on iOS. I know you guys are busy, but is there any update on this or do you know a workaround?
After this exception occurs, you can reconnect the peripheral but discoverServices and subscribeToCharacteristic fail. I found the workaround is to disconnect/reconnect the peripheral after the failure.
I am experiencing the same issue. Is there any update or workaround to fix this issue?
@shobhit14gupta not yet.
I am also experiencing the same issue. Has anyone got fix for this issue?
Yep, still seeing this as a problem.
Still happens to me on iOS 15 and iPadOS 15
I see a lot of pull requests being stuck, if I fix this and make a PR what are the chances this gets merged and released?
I have the same Issue. On IOS only as well.
I found something that might be helpfull in another issue : #414 https://github.com/PhilipsHue/flutter_reactive_ble/issues/414#issuecomment-1013830555
The comment says : "_I had the same error. I was able to fix it by canceling the BLE Characteristic Streams first, adding a delay of a few hundred milliseconds then canceling the ConnectionStateUpdate stream.
example
await characteristicStream?.cancel(); await Future.delayed(const Duration(milliseconds: 300)); await deviceConnectionStateStream?.cancel()_; "
I am in the same situation of having subscribed to a characteristic. [EDIT] I tried the fix, and it is WORKING for me ! :D
I though that might help some of you.
Thanks for the sample @GaelleJoubert. I am using the mcumgr-dart library and found that adding a delay between closing the mcumgr client and cancelling the connection solved the problem for me.
Suggestion from @GaelleJoubert works. I had to add delay after canceling characteristic stream before I disconnected from the device.