Core Bluetooth and backgrounding: Detection of a device and triggering an action, even after being days in background mode?

后端 未结 3 1360
猫巷女王i
猫巷女王i 2021-01-30 02:38

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.

3条回答
  •  执笔经年
    2021-01-30 03:06

    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:

    • Continue to support bluetooth-central as a background execution mode.
    • Opt into state preservation and restoration, as documented here under "Adding Support for State Preservation and Restoration".

提交回复
热议问题