3

Does anyone know if core BLE continues to run in the background after a user force quits the app in iOS 7.1? Or does just iBeacon continue to run? I know that neither will continue to broadcast on force quit, but will both continue to scan?

EDIT: I've attempted to test the current implementation I've had and it doesn't appear to be running in the background after force quit. What I've heard so far from other sources is that it does but it doesn't appear to be running for me with the standard CoreBluetooth implementation.

Taylor
  • 65
  • 1
  • 8
  • possible duplicate of [How is iBeacon support REALLY changed in iOS 7.1?](http://stackoverflow.com/questions/22363652/how-is-ibeacon-support-really-changed-in-ios-7-1) – Daij-Djan Mar 15 '14 at 17:48
  • I know that iBeacon has changed - I'm asking if this change affects core BLE too. My implementation does not use iBeacon. It just uses core BLE. – Taylor Mar 15 '14 at 18:39
  • 2
    This is definitely not a duplicate and a very reasonable question. Only that it would be better if the SO showed some effort of trial. – allprog Mar 16 '14 at 18:51

2 Answers2

3

For CoreBluetooth (CBCentralManager and CBPeripheralManager), the following rules apply:

  • If the user closes the app manually using the app switcher, the BLE part of your app also gets killed.
  • If the user does not close the app manually, you can use the bluetooth-central and bluetooth-peripheral background modes to get relevant callbacks while your app is backgrounded. However, iOS may still kill your app under memory pressure or for whatever reason, in which cases the BLE part is also gone.
  • To keep the BLE part alive, you can use restore identifiers when instantiating CBCentralManager and CBPeripheralManager. Managers with a restore identifier are kept alive even after iOS killed your app, and if an interesting BLE event occurs), your app will be launched into background and you will be passed the state of the managers when the app got killed for restoration.
    • The main queue is suspended during background execution - make sure to configure the managers in a way that events are not dispatched on the main queue.
    • If the user closes the app manually using the app switcher, restoration is forfeited and the BLE part of your app won't stay alive.
    • To test restoration, you need to resolve to using tools like BackgroundKill. Note that the Xcode debugger may keep your app alive, so make sure to disconnect the debugger first (which will kill the app), then launch your app, then open BackgroundKill and examine the Console output in the Xcode Organizer window.
Etan
  • 17,014
  • 17
  • 89
  • 148
  • So essentially 7.1 does not change anything about CoreBluetooth in terms of running in the background? Only iBeacon works after a user quits the app through the switcher? – Taylor Mar 17 '14 at 17:40
  • @etan: You're saying that the main queue is suspended in background mode. Can you please elaborate how you retrieved this information? I am dispatching to the main queue from a background queue in background mode to avoid thread synchronization problems when app foregrounds, i.e. core data access is dispatched to the main queue from my bluetooth queue. In my experiments the main loop _is_ running in apps launched in background mode. Can you please elaborate on your experiences? – Lars Blumberg Jan 11 '17 at 12:28
0

Yes, it continues to run. This is a change in iOS 7.1.

See my detailed answer and test procedure in the comments here: https://stackoverflow.com/a/22365156/1461050

Community
  • 1
  • 1
davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • I saw this answer, but does that include core BLE? Or just iBeacons? i know that iBeacons will continue to scan but my implementation just uses core BLE not iBeacon. – Taylor Mar 15 '14 at 18:37
  • 1
    OK, so to be clear, you want to know if the CoreBluetooth APIs will wake up an app in the background after the app has been killed in iOS 7.1. I have not tested this. The answer may be specific to the CoreBluetooth APIs you are using. Do you have a code snippet you can share with specifics? – davidgyoung Mar 15 '14 at 19:21
  • Yes, that is what I'm asking. We use the CoreBluetooth APIs (peripheral and central) to find other users around you – Taylor Mar 15 '14 at 19:47