The subject says it all, really. Documentation, insofar as it exists at all, suggests that apps written against the CoreBluetooth framework running on iOS devices can add "bluetooth-central" to their background privilege list and so process some kind of Bluetooth events whilst inactive, but which exact events do and do not get delivered?
For example:
The Background Fetch API provides a method for managing downloads that may take a significant amount of time such as movies, audio files, and software.
Nobody seemed to know, so I bought an iOS developer account and ran some experiments. Here's what I found:
When running in the foreground, you can start a scan using CBCentralManager::scanForPeripheralsWithServices. Your scan can be restricted to devices advertising a particular service, or unrestricted (pass nil for that call's parameter). It can also allow or disallow duplicates; in the former case you'll get a didDiscoverPeripheral callback every time the iPhone receives an advertisment packets; in the latter you'll only get one callback per device found.
When you enter the background, the rules appear to be as follows:
I don't know whether connect attempts to nonconnectable devices (e.g. BLE Advertisers, like those implementing the proximity profile) is good enough as my example devices are connectable. However at least for connectable devices, this scan/connect/disconnect/scan procedure suffices to poll for a device's presence in the background.
The above results were gathered using an iPhone 4S running iOS 5.0.1
In addition to Chris's answer:
peripheral:didUpdateValueForCharacteristic:error:
) from the peripheral in background, even after 10minutes.So when you want to continuously run in background you have 2 options:
Later should be the "Event backgrounding" from WWDC 2012 Core Bluetooth videos https://developer.apple.com/videos/wwdc/2012/ But the former looks like a hack, I don't want to rely on it.
I tested this on iPhone5, iOS6.1.4
Apple finally released the Core Bluetooth Programming Guide and here's the official note about
Core Bluetooth Background Processing for iOS Apps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With