What does it mean for background processing of Bluetooth data to be 'session-based' in iOS?

605 views Asked by At

In Apple's documentation for Background Execution it is explained that 'Any app that supports the background processing of Bluetooth data must be session-based. ... Apps must provide an interface that allows the user to start and stop the delivery of Bluetooth events. That interface should then open or close the session as appropriate.'

Our iOS application acts as a CBPeripheralManager in communication with a CBCentralManager on OS X. We have problems preventing the app from becoming suspended and becoming unresponsive to communications from the Central Manager.

We are declaring UIBackgroundModes key with the bluetooth-peripheral value in the app’s Info.plist file, which should get iOS to allow us to operate in background with reduced limitations. While in background our app processes communications from the central and replies as expected for many hours, but eventually gets suspended.

The documentation implies we should be managing a session, perhaps in the way that NSURLSession manages a session, but there is no such thing as NSSession, nor CBSession, and I can find no other mention of Session in releationship to Core Bluetooth in the documentation.

Any ideas?

1

There are 1 answers

5
Neo On

I am also developing a similar App but our App is in Central mode

If you read this guide Core Bluetooth Background Processing for iOS Apps

specially the section "State Preservation and Restoration"

you will see that it says

Core Bluetooth supports state preservation and restoration for apps that implement the central role, peripheral role, or both. When your app implements the central role and adds support for state preservation and restoration, the system saves the state of your central manager object when the system is about to terminate your app to free up memory (if your app has multiple central managers, you can choose which ones you want the system to keep track of). In particular, for a given CBCentralManager object, the system keeps track of:

Apps that implement the peripheral role can likewise take advantage of state preservation and restoration. For CBPeripheralManager objects, the system keeps track of:

  1. The data the peripheral manager was advertising

  2. The services and characteristics the peripheral manager published to the device’s database

  3. The centrals that were subscribed to your characteristics’ values

You can also read how to Add Support for State Preservation and Restoration on the same page below

hope this helps you