react-nativebluetoothbluetooth-lowenergyios-bluetooth

Bluetooth still active after app killed using react native


I have a problem with the lifecycle of Bluetooth on iOS.
We are using React Native and the following library (https://github.com/innoveit/react-native-ble-manager) to manage our Bluetooth devices.

The devices sends data and clears its local data when it has sent all its data through bluetooth (we are only using ble messages ACK, no internal app ACK).

The problem is, that iOS seems to maintain the ble open when the app is killed, which is making the device think that it is still sending data that is processed correctly by our app, and clears it at the end (which causes data loss).

Is this a normal behaviour on iOS ? (the fact that the ble stays open for some time after the app is killed, and no errors are sent through ble ?)

Is there a way to force close the ble when the app is killed ?

Thanks


Solution

  • Is this a normal behaviour on iOS ? (the fact that the ble stays open for some time after the app is killed, and no errors are sent through ble ?)

    Yes, this is normal. The OS holds open the connection and shares it with apps. The apps do not hold connections directly. It can take some time (generally on the order of seconds, but sometimes a bit longer) for the OS to drop the connection after the last app releases it.

    Is there a way to force close the ble when the app is killed ?

    No. There is no way to do anything when the app is killed (by which I assume you for force-quit, for example by swiping up on the app switcher).

    All that said, I'm a bit surprised here that you're getting a write response back to the device if the app is no longer reading. When you say "ble messages ACK," specifically which "ack" do you mean? Are you getting a Write Response packet back? Or do you mean a lower-level ack?