iOS, turning off bluetooth radio and peripheral.state #954
Replies: 1 comment 2 replies
-
Bluetooth state handling on iOS has not yet been thoroughly tested, so it is possible it is being handled incorrectly on iOS. Ultimately, Kable aims to have the platforms be as consistent as possible; so the situation you're describing ( On Android, when bluetooth is turned off, peripherals remain connected, but strange behavior around that can ensue — so, Kable makes sure to explicitly drop connections. Explicitly closing connections on iOS may not be needed, but we rely on the system to deliver us connection state. So, if iOS is automatically killing connections for us, then I'm really surprised it doesn't send us a disconnect event. Definitely worth investigating further. The questions I'd need to test (when I have time) are:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I considered opening an issue for this, but I'm not sure if I'm using the library wrong. So I opened a discussion instead.
My question is : On iOS, given a peripheral with an active connection, should turning off the Bluetooth radio result in the
peripheral.state
flow emitting aDisconnected
state?In my app I never see this. On Android it works a 100% of the time but on iOS I see the following sequence of events in the Kable logs. Disconnection always times out after 5 seconds; and the
Disconnected
state is never emitted. Since things work as expected on Android, I'm assuming this might be something I'm doing wrong.From my reading of the source, it looks like there are 2 components at play here
onBluetoothPoweredOff
inCBPeripheralCoreBluetoothPeripheral.kt
onDispose
inConnection.kt
.It looks like for some reason, when
onBluetoothPoweredOff
happens, thendisconnect
is also being called. My guess is thatCBCentralManager.cancelPeripheralConnection
is only allowed to be called when the Bluetooth radio is powered on and that explains the rest of the log output.However, what I don't understand is: Why is
onBluetoothPoweredOff
eventually callingdisconnect
in Perpiheral.kt? Could it be something do with the coroutine scope that I'm using to collect theperipheral.state
flow?Does anyone have any ideas?
Beta Was this translation helpful? Give feedback.
All reactions