Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreBluetooth Background Scan Device

I am currently working on an app that requires me to scan a device using Bluetooth 4.0. At this point I have encounter a problem.

Is it possible to have the app scan the device when the app is running in the background? For some reason, the app cannot scan the device. The app did not call didDiscoverPeripheral while it was running in the background. However, my app can receive data from the device once connection has been establish.

To make things simpler, why can't my app scan the device while it is running in the background?

P.S. I did input the Required background modes 1.App communicates using CoreBluetooth 2.App shares data using CoreBluetooth

like image 815
user1068895_CHU Avatar asked Dec 14 '12 05:12

user1068895_CHU


People also ask

What is background Bluetooth?

The bluetooth-central Background Execution Mode plist file, the Core Bluetooth framework allows your app to run in the background to perform certain Bluetooth-related tasks. While your app is in the background you can still discover and connect to peripherals, and explore and interact with peripheral data.

What is active scan in BLE?

A device may use active scanning to obtain more information about devices that may be useful to populate a user interface. Active scanning involves more link layer advertising messages. So, for any usecase it will not be necessary to differ between those two scanning types.

How do I enable BLE on my Iphone?

On your iOS device go into "Settings-> Bluetooth" and turn on your BLE device. You should see the device listed in your available devices.


1 Answers

Scanning in the background is a very slow process. Apple says it's 55 times slower than in the foreground. My experience shows that it can be even slower. So in order to scan for a device in background keep in mind the following:

  1. Make sure the other device is advertising at max speed (20ms) and advertises the services that you are scanning for. There is an example in this answer for that: https://stackoverflow.com/a/18113505/768935
  2. Due to the reduced scanning speed, give much more time for the app to find the device.
  3. Make sure you start scanning with the services specified. You cannot scan in the background for nil services.
  4. The allow duplicates option for scanning is ignored in the background.
like image 100
allprog Avatar answered Sep 30 '22 12:09

allprog