CBPeripheralManager and Background Modes
OS : iOS 6.x Platform: iPhone 5
I am seeing what appears to be an issue when enabling Core Bluetooth background services for CBPeripheralManager applications. (I am NOT seeing these issues with background execution for CBCentral clients).
First, there appears to be a discrepancy in the iOS documentation as to how to enable background processing for Core Buetooth in the Information Property List Key Reference:
This link identifies UIBackgroundMode values associated with the CoreBluetooth framework as “bluetooth-central” and “bluetooth-peripheral”. However, when editing the Info.plist file for my project the two CoreBluetooth values for Required background modes are “App communicates using Bluetooth” and “App shares data using CoreBluetooth”.
I believe the correct choice for enabling background operation for CBPeripheralManager peripheral applications is “App shares data using CoreBluetooth”, although I have tried both and neither work as expected. Let’s assume “App shares data using CoreBluetooth” is correct and look at the behavior.
When “App shares data using CoreBluetooth” is added as a background mode in the property list, an alert occurs when the application is first launched allowing the user to confirm that the device should allow Bluetooth sharing. A Privacy setting is created in the Settings for the device as expected. This is good!
However, simply adding this background mode to the plist adversely effects the CBPeripheralManager App when launched and run only in the foreground. Bluetooth clients, running on different iOS devices than the peripheral, which connect to the peripheral can no longer discover all of the services published/exposed by the peripheral. Only three of the services exposed by the peripheral are discovered after enabling the background mode to “App shares data using CoreBluetooth”. This impact on client code is reproducible on every BLE Client I have access to, my own scanner, LightBlue from the App Store, and TI’s Multitool from the App store. Turning the background mode off restores correct service discovery by all the clients.
The adverse foreground behavior is identical when the CBPeripheralManager is started in the foreground, advertising is enable, and then the app is moved to the background. Clients on different iOS devices can discover the backgrounded peripheral, connect and discover services but not the full complement of services offered by the peripheral device.
Again, the correct foreground behavior can immediately be re-established by simply turning off the background mode in the property list.
Any one else have experience with background processing and CBPeripheralManager?
-Chip
|