iOS ble scan on background

I have been developing an app that scan ble device and check distance.

If distance is reached defined value an app conect to device and comunicate with the device.


I am wondering if I can scan on background like foreground.


I have tested many times and figured out some test result.


1. There are two test app. Each app can scan on foreground and background.

2. A app is on background and another app is scaning on foreground.

3. The app on background get called "- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI" frequently like on foreground with CBCentralManagerScanOptionAllowDuplicatesKey : @YES.

4. If I scroll up on spring board to show small setting screen, the app on background get called like 3.


I know CBCentralManagerScanOptionAllowDuplicatesKey is ignored when a app is in background. But the result is wired.


If an app scan in background like foreground, How can I do that?


Finally, I downloaded an app at app store and the app uses corelocation and corebluetooth framework. The app can scan ble on background like it is in active and comunicate with ble device all the time. Even if I terminated the app and reboot my iPhone the app can scan.

Accepted Reply

CoreBluetooth apps in the background cannot scan for peripherals like they do in the foreground.


A background app can expect a single didDiscoverPeripheral() callback per peripheral per scan.

Additionally, when a scanning app is in the background, the scan rate will slow down dramatically, therefore even if you were to receive multiple callbacks, there will be a lot of advertising packets missing.


Any apps that might claim to scan continuously while in the background are either mistaken, or are abusing the CoreBluetooth API in a manner that might cause issues in the long run.


Finally, I would like to mention that it has been determined by the industry that RSSI is a poor estimator for distance. Various factors like reflections, scattering of signals, and other physical properties of the environment make RSSI unsuitable for distance estimation. You can do a quick search yourself to find a number of articles and papers on this subject.

Replies

CoreBluetooth apps in the background cannot scan for peripherals like they do in the foreground.


A background app can expect a single didDiscoverPeripheral() callback per peripheral per scan.

Additionally, when a scanning app is in the background, the scan rate will slow down dramatically, therefore even if you were to receive multiple callbacks, there will be a lot of advertising packets missing.


Any apps that might claim to scan continuously while in the background are either mistaken, or are abusing the CoreBluetooth API in a manner that might cause issues in the long run.


Finally, I would like to mention that it has been determined by the industry that RSSI is a poor estimator for distance. Various factors like reflections, scattering of signals, and other physical properties of the environment make RSSI unsuitable for distance estimation. You can do a quick search yourself to find a number of articles and papers on this subject.