Start bluetooth scan after wake up from iBeacon

Hi there,


i'm currently working on an iOS app that uses a combination of CoreBluetooth and CoreLocation to interact with BLE devices from the background. We want our app to wake up, after one of our beacons is detected. After that we need to start a BLE scan to receive additional informations about the device from their scan response and notifing the user about the device via a user notification.


Currently, the app always wakes up when entering our beacon region. In the console app of the connected Mac, we can see that the bluetooth scan is triggered again. But the didDiscoverPeripheral callback will never be called. We registered the `bluetooth-central` role in our `info.plist` and also specify a concrete service UUID to scan for, but still there's no response when the app is restarted. We also created a serial background queue for our CBCentralManager and registered a restore identifier.


Everything works fine when the app runs in foreground or is send to background. But after the application is killed via the task manager (double tap on home button and swipe up) the bluetooth scan cannot be started again.


This is our current test scenario:


  1. Launch App via XCode
  2. Kill app via task manager (double tap on home button and swipe up)
  3. Enable iBeacon device
  4. App receives enter region event and wakes up
  5. App starts bluetooth scan with concrete service UUID and without duplicates
  6. `centralManager(_ :, didDiscover:, advertisementData: , rssi:)` is never called


Is there something we are missing?

Replies

The problem is that you are force-killing the app via task manager (double-tap-swipe-up). When the user force-kills an app in this way, iOS assumes that the user is king, and does not want the app to be running. An app cannot be awakend when force-killed by the user for *any* reason until the user relaunches the app themselves.


An iBeacon can relaunch an app that is killed in any other way by the OS itself (out of memory, too much background processing, not giving the main run loop enough time to run, etc.), but not when it is killed by the user.


See this Stack Overflow post, which links to the relevant Apple developer docs and WWDC videos:

https://stackoverflow.com/questions/19068762/will-ios-launch-my-app-into-the-background-if-it-was-force-quit-by-the-user

iBeacon can relaunch your app even if user force-killing the app, Pls look at his test scenario, the question is "bluetooth scan is triggered but can not receieve scan callback"