iOS - Bluetooth Low Energy in the Background

The Apple documentation is I believe correct although in places it isn't as explicit as I would prefer. This short article aims to explain what you can and cannot do in the background and the behaviour you will see. This information is relevant for iOS 7. [Update: If iOS 8 is different I will try to revise this post at a later date.  iOS 8 behaviour appears the same in my initial testing and I couldn't find any significant changes documented and there was no CoreBluetooth talk at WWDC 14.] If you think anything is inaccurate please let me know I don't want to mislead anyone and my testing hasn't been extensive.

Not Quite Enough for Peer to Peer Applications

My summary of the situation is that you can't do quite enough to support peer to peer in a viable way unless you have an app that you expect to be run on a regular basis anyway because the background modes (except for iBeacon detection) do not persist through a reboot of the phone or a flat battery. This means that the user will fall off your peer to peer application framework.

iBeacons can awake apps that have not been running since a reboot but iOS devices can only themselves perform as iBeacons in the foreground.

What Devices Support Bluetooth Low Energy (and background operation)?

iPhone 4S and later, iPod Touch 5G, iPads except the iPad 1 and 2.

What Can iOS Devices Do in the Background (Bluetooth)?

  1. Be notified of iBeacons matching a particular UUID in the local vicinity.
  2. Advertise as peripheral device by UUID.
  3. Act as central manager and scan for peripheral devices by UUID.
I believe though I haven't tested that (1) is fully able to survive a phone reboot or battery loss and that the phone will resume scanning for such iBeacons when turned back on. When a beacon is found the app will be allowed to run for a short period to process the information and possibly request that the user be alerted.

(2) and (3) on the other hand survive being put into the background and if the App has been terminated due to memory pressure and is no longer running in the background the App will be resumed for a short period to process the connection. However if the App is closed by flicking up from the app switcher or if the phone has been shutdown, run out of battery or rebooted then the background bluetooth services will not be resumed so your app will never be alerted.

Can't the iOS device be an iBeacon?

Only while the app is in the foreground, I don't believe it is possible to support this in the background at all.

Why Would I Want to Do Peer to Peer in the Background Anyway?

Well there are apps like AroundThen which try to use Bluetooth Low Energy to enable you link to people you have met (been in close proximity) to your online social networks. This seems a reasonable case and there are probably more that I haven't considered either

Potential Workarounds

Heavily Used App

If you are Facebook you may be able to rely on sufficient usage of your application to have a good coverage for a peer to peer Bluetooth service to be effective. Enough people will run your app anyway within a few hours of rebooting the phone that you can still get some super local contact exchange happening.

Rely on Android iBeacons...

I haven't tested this approach but if Android devices can perform as iBeacons  in the background (which I haven't tried and may not be possible) you could register to be awoken on contact with an iBeacon and then start to advertising and scanning as a BLE peripheral and central manager. I haven't tried doing this triggered by the iBeacon either.

This approach if it works could allow the population of Android users of an app to keep the iOS users within the peer to peer group. You still need a critical mass of devices (particularly Android ones) there for the app to really work.


8 responses
Great article. It would be great if you could also add iOS device versions/names that support BLE. Thanks,
Did anything change with IOS8?
@darwin2k I'm not aware of any iOS8 changes that are relevant but I haven't tested. I'll post a new story if I get round to testing it.
Have a look at this: https://github.com/CharruaLab/AltBeacon Sounds quite interesting!
I think I looked at an earlier version of AltBeacon when I was developing the test software. I don't think it fundamentally works around the power off loss of listening/advertising state (if I'm wrong let me know). I've done a retest on iOS8 deliberately closing the app, turning off the device or running out of battery ends the listening/advertising state and it doesn't restart when the device does.
Take a look at this: https://developer.apple.com/library/ios/documen... State preservation might do what you want.
2 visitors upvoted this post.