Thanks a lot for getting back so quickly & your detailed response! The problem I'm trying to solve is to reliably sync data from a BLE peripheral in the background over a longer period of time — either during the day or the night — between our user opening the app.
There's a mix of technologies which can make this work. First, and foremost, CoreBluetooth has its own background architecture. That background architecture is extremely powerful, including support for relaunching the app into the background. That actually leads to another question, namely, what is your app actually doing when it's terminated? The system has a complex system for determining with which process it should terminate, but I'd generally expect it to avoid terminating apps that are engaged in active Bluetooth communication. More to the point, assuming your app is engaged in active Bluetooth communication, I wouldn't really expect to have even suspended, a Bluetooth exchange generally happens fast enough that the system never suspends you.
In terms of other system support, I see a few different options:
-
If the user is initiating the transfer, then BGContinuedProcessingTask would let you extend foreground runtime for several minutes.
-
For longer, user-initiated, transfers, you could use a Live Activity to provide custom feedback about what's going on while also extending your run time.
-
If you specifically want the transfer to be a "background" transfer that doesn't disrupt the user, then using BGProcessingTaskRequest to "start" the transfer window might work reasonably well. The processing task itself will give "a few minutes" of run time; however, the other point is that the processing task time window is specifically chosen to minimize the possibility of the user interacting with their device AT ALL. In practice, I'd expect that to GREATLY reduce the likelihood of your app being terminated due to memory, as the device is unlikely to be generating the same kind of memory contention and "spikes" normal user usage does.
I think the biggest question here is how much time you actually need, as the more time you need to complete the work, the harder it's going to be to "guarantee" that time, particularly if the work can't be done progressively but must be completed in a single session. If you specifically need a large chunk of continuous runtime, then the best approach is to do with the user’s involvement (1 or 2).
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware