Connect peripheral and central BLE in background mode ?

Hello,

I need to connect two devices using an application which is in background mode in order to transfer some data through bluetooth LE.

My research and tests, proved me that, I am able to scan the network for a specific service UUID.

After that, no connexion seems to appear. If I open the device which acts as a peripheral or the device which acts as central, the connexion is established, and I can receive the datas stored in GATT characteristic.

I'm developing an app with react-native framework. Could you tell me if what I intend to do is possible ? Maybe with native code ? Or neither.

Thank you for your answer.

Regards,

Alexandre

Answered by Engineer in 687982022

Due to the limitations put on backgrounded apps by the system, it is not going to be practically feasible to have two iOS devices to be able to detect each other when both apps are in the background.

In general, advertising for apps is done on a best effort basis. As Bluetooth is a shared resource, when other apps and system resources need to use Bluetooth, advertising for apps in the background will slow down, and may even stop for short periods of time. The rate of advertising is directly related to the probability and time required to be discovered by a scanning device.

On the scanning side, the scan rate also drops once the app is in the background. Scanning rate is also directly related to a timely discovery. Also, both these rates will further slow down when the phone screen goes off, and even further down after a while when the phone goes to sleep mode.

Unfortunately, all these restrictions and slowdowns end up making the discovery process very slow, to the point of becoming unusable. It could potentially take minutes, if not longer. So, if your use case is that the two devices detect each other promptly when they get close to each other, and both devices are locked, it will probably not going to work as you hope it did.

As these limitations in behavior is systemwide, and by design for power management purposes, there are no workarounds to avoid these changes outside of trying to keep at least one side in the foreground.

Accepted Answer

Due to the limitations put on backgrounded apps by the system, it is not going to be practically feasible to have two iOS devices to be able to detect each other when both apps are in the background.

In general, advertising for apps is done on a best effort basis. As Bluetooth is a shared resource, when other apps and system resources need to use Bluetooth, advertising for apps in the background will slow down, and may even stop for short periods of time. The rate of advertising is directly related to the probability and time required to be discovered by a scanning device.

On the scanning side, the scan rate also drops once the app is in the background. Scanning rate is also directly related to a timely discovery. Also, both these rates will further slow down when the phone screen goes off, and even further down after a while when the phone goes to sleep mode.

Unfortunately, all these restrictions and slowdowns end up making the discovery process very slow, to the point of becoming unusable. It could potentially take minutes, if not longer. So, if your use case is that the two devices detect each other promptly when they get close to each other, and both devices are locked, it will probably not going to work as you hope it did.

As these limitations in behavior is systemwide, and by design for power management purposes, there are no workarounds to avoid these changes outside of trying to keep at least one side in the foreground.

Connect peripheral and central BLE in background mode ?
 
 
Q