I posted here https://developer.apple.com/forums/thread/805554?page=1#867766022 but posting again for visibility (and let me know how I can file a bug)
There was a response in that thread that said you could use the childProgress system to help updating progresses to keep the backgroundTask alive.
What I've found is that using childProgresses results in more terminations than if you just updated the progress directly.
Here is my setups to test this
- A BGContinuedProcessingTask that uses URLSessions to upload, and registers the task.progress with the Urlsession Progress
- Same, but the task.progress gets updated via a UrlSession Callback
The second is MUCH more stable out in the field in cellular settings, the first fails extremely frequently.
My suspicion is that in the documentation here https://developer.apple.com/documentation/foundation/progress#Reporting-Progress-for-Multiple-Operations
it explicitly states
The completedUnitCount property for a containing progress object only updates when the suboperation is 100% complete. The fractionCompleted property for a containing progress object updates continuously as work progresses for all suboperations.
I wonder if BGContinuedProcessingTask is only looking at completedUnitCount for progress, and not fractionCompleted?
In either case, I would love to use the childProgresses because there are bugs with retries by updating the progress manually, so would love some help resolving this, Thanks!
Update: I just tried replacing the child progress with a URLSessionDelegate that updates the progress completedUnitCount directly, and it seems to be more stable (but I only tried this once). Potentially a bug with using Child Progresses to keep alive BGContinuedProcessingTasks?
Yes, that's very likely. This is something that "should" work, but there are also a lot of edge cases and details to cover. I expect this will improve over time; however, please file a bug on this and post the bug number back here.
Having said that, my other question is what does the progress UI look like during this time? The primary purpose of progress here isn't to keep your app awake; it's to make sure the user knows what's going on. Similarly, I suspect the big problem here isn't that your task is expiring; it's that your progress bar isn't showing any progress!
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware