BackgroundTasks not running in reasonable amount of time?

Here is what I'm trying to do:
Users in my app will generally be offline while they use the app to gather data. Then they will move back into WiFi range. I'd like the iOS to trigger a background task when they come back online to upload the data.

What I've tried:
When the app goes into background mode I submit a BGProcessingTaskRequest
(request.requiresNetworkConnectivity = true).
I've called _simulateLaunchForTaskWithIdentifier from XCode and everything works perfectly.

The problem is that I can't get the background task to trigger for real. I've sat with the app backgrounded with WiFi for a half an hour and nothing uploaded. How long should I expect it to take? Should I be using BGAppRefreshTaskRequest for this use case?

How long should I expect it to take?

As a general guideline, processing tasks (BGProcessingTaskRequest) will typically run overnight (assuming that the device is connected to power).

Should I be using BGAppRefreshTaskRequest for this use case?

You can try that, but there’s no guarantees that it’ll help. The system’s logic for scheduling app refresh tasks is complex and there’s no simple guideline as to what to expect. See WWDC 2020 Session 10063 Background execution demystified for more background on this.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
BackgroundTasks not running in reasonable amount of time?
 
 
Q