Standard CoreBluetooth advertisements can broadcast while the app is in the background, but not if they were started with CLBeaconRegion dictionary. The workaround is to ditch CoreLocation framework altogether and create your own proximity “framework” using only CoreBlueTooth.
You still need to use the appropriate background specifiers in the Info.plist file (e.g. bluetooth-peripheral and bluetooth-central).
The code looks something like this:
1) create a standard peripheral advertisement using CBPeripheralManager
1 2 3 4 5 |
|
2) use use CBCentralManager
to scan for that service using the UUID you specified.
1 2 3 4 |
|
3) in the CBCentralManagerDelegate
method didDiscoverPeripheral
, read the RSSI value of the advertisement.
1 2 3 4 5 6 |
|
4) Translate the RSSI values into a distance.
1 2 3 4 5 6 7 8 9 10 11 |
|
I found that I needed to “ease” or “average” the RSSI values to get anything workable. This is no different than when you are working with any sensor data (e.g. accelerometer data).
I have this concept fully working hope to publish it somewhere at some point.
Also, use the docs (Core Bluetooth Programming Guide) if you get stuck.