I managed to get this to work with scanning in the background (along with connecting and transmitting data). There is an important difference between how your application was terminated and if iOS saves and restores your primary Bluetooth manager.
The addition “Application communicates using CoreBluetooth” to “Required Backgrounds” in Info.plist covers most situations. Your central manager will continue to work in the background - either when the user presses the home button or locks the phone (or both). However, you will never get the delegate call "willRestoreState" in these scenarios, since your central manager is still being processed by your application (it is still in memory).
Saving and restoring only takes effect in one scenario - your application was interrupted by iOS due to memory limitations. The easiest way to get this to test the loading of three games with intensive memory, while your application is in the background. If you look at the device console, you are waiting for this message:
"Apr 4 13:16:47 Michaels-iPhone SpringBoard[58] <Warning>: Application 'UIKitApplication:com.oculeve.TearBud[0x6df4]' was killed by jetsam."
At the moment, iOS will take over the central manager. If it scans, it will continue to scan; if it connects to a peripheral device, it will continue to connect. If you get a call from the central manager delegate (didDiscoverPeripheral, didUpdateValueForCharacteristic), iOS will launch your application in the background again. At this point, you will receive an invitation from the willRestoreState delegate . At this point, your application will return to memory and will work as described above. Please note that you will need to do some recovery in willRestoreState if you were connected to the device. All of this is described in a video with Bluetooth support in WWDC 2013 format.
It seems that the kicker that restore / save does not work if you manually close the application from the system tray (by scrolling the application). I assume that Apple reasoned that in this case the user explicitly closes the application, and all Bluetooth communication should stop. This is also true when the user restarts his phone. I assume that this is due to the fact that rebooting is basically equal to scrolling up to close all applications in the system tray. If you get to this point, you can only reconnect after the user opens your application again.
Something that needs to be noted is that your application is in the system tray does not mean it in memory.
Why Apple doesn’t just tell you this, the documentation goes for me.
source share