iOS BLE - How to keep app active in the background

2020-07-30 00:28发布

问题:

I am trying to find a clever way to keep a BLE app active in the background on iOS 6, without breaking any of Apple's rules. I plan to use the phone as a peripheral device and another BLE circuit as the central. My app will automatically be opened when a user arrives to a building using geofencing. After that the iPhone will connect to the first BLE central device it sees (the device will be in its white list). The user will then be able to move throughout the building switching to different BLE "nodes".

My question is: What do I need to do in the background when a user is stationary at their desk so that the app does not get suspended due to memory resources?

My idea is based on this solution for a separate problem: There could potentially (not regularly) be 10-50 users in an area with only a few BLE "nodes" and I read at bluetooth.org that I could setup a dynamic connection system, basically rotating connections through all the users.

My idea is to setup a similar dynamic system where the central device (not the iPhone) disconnects the device on regular intervals (30-40 minutes) and then the iPhone will reconnect.

Is this something that some feasible? Is this against the iOS development guidelines? I was unable to find anything explicit about this. I have also asked on the iOS developer forum, but unfortunately it is not as popular as this site.

Thanks in advance!

回答1:

Xcode -> Project target -> Capabilities -> Enable background mode

Check Uses Bluetooth LE Accessories

Capabilities

Also enable the following key in .plist file

Required background modes

App communicates using CoreBluetooth

Plist