I\'ve written an app that needs to get informed when a certain Bluetooth Low Energy device comes within range. If the BLE device gets noticed my app just stores a timestamp.
As of iOS 7, your use case is now easy to support. Before iOS 7, your application could register for notifications about that peripheral, and it would be woken up in the background when the system had notification to deliver. However, if the system came under memory pressure while your app was backgrounded, or was rebooted, it wouldn't be relaunched. iOS 7 added state restoration to CBCentralManager
and CBPeripheralManager
, so now the OS will relaunch your application in a limited capacity even if it wasn't running due to either of the aforementioned conditions. See the CoreBluetooth guide for more info.
In short, for your use case, you could do the following:
bluetooth-central
as a background execution mode.No, iOS gives no guarantee that your app keeps alive in the background. The docs say:
However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason.
(Documentation of applicationWillTerminate)
Use IOS7 BLE State Preservation & Restoration
If your app is terminated by IOS, due to memory pressure(this is why your app can't work after days), it can't handle bluetooth delegates anymore. In this case, if you used State Preservation & Restoration, your app can be relaunched to background to run again, also for only 10s. After 10s, it would move to suspended state. Only in this situation, CBCentralManager's willRestoreState can be triggered.
Good luck.