Proper method of uploading large amounts of files in the background

I am working on an application that needs to upload a large number of files to a server and would prefer to do this in the background to not impact the user experience.
I've read up on all the new ios 13 BGTasks (processing and app refresh) and after downloading the example project from Apple (color feed) and other projects from 3rd parties trying to show how to implement it; none of the projects are working and the tasks are never getting called. I've tried everything I could think of and all permutations of having the device plugged in or not and setting the tasks to need power/network or not and have not gotten a single successful trigger of either an app refresh or a processing task. The documentation by Apple is rather lacking and the only real direction we are given is to simulate a trigger using the console.
So my question is, are these tasks even useful for uploading data in the background (as I assumed the processing task would be) or is there a better method of it? Or is uploading of files in the background just not something iOS really allows?

Answered by DTS Engineer in 406639022

How can I give my processing task the best chance of getting run?

In production, my experience is that these task tend to run overnight if the device has mains power. During development, you can use the facility described in WWDC 2019 Session 707 Advances in App Background Execution.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

It is possible to using BackgroundTasks framework to run network requests. Specifically,

BGProcessingTaskRequest
is useful in situations where you can’t use the follow. But…

In general, I recommend using an

NSURLSession
background session for background transfers. The API has been around for a long time and it’s specifically designed for this networking use case.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

In this case I've got a few things working against NSURLSession. 1) We have a large number of uploads (images/videos/etc) that we cannot do in bulk, and the guidelines mention using less background sessions and instead make them larger and 2) We are using the Firebase SDK for our uploads and they don't seem to have a configurable way to set the uploads as needing to use the background NSURLSession.
Which is why I was really excited to learn about BGProcessingTasks, but then equally dismayed when nothing I did ever triggered them. How can I give my processing task the best chance of getting run?

Accepted Answer

How can I give my processing task the best chance of getting run?

In production, my experience is that these task tend to run overnight if the device has mains power. During development, you can use the facility described in WWDC 2019 Session 707 Advances in App Background Execution.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

"After digging in deeper and more thoroughly these are my results (for anyone else who might find this thread and have similar questions).
1) Refresh tasks and processing tasks are scheduled and trigger at what seem to be the same time. So just because refresh tasks are shorter they do not get triggered any more often than a processing task.
2) If you want to have any sort of reliability to your tasks you should set the task "requiresExternalPower" to TRUE. This is the most important step. If you set this to false you are in fact reducing the chance of your task being triggered even if the user keeps their phone plugged in! So unless your use case involves a user who would go long periods of time w/o plugging in their phone you should never set this to false. At least until apple updates whatever logic they are using to determine when tasks are triggered.

Proper method of uploading large amounts of files in the background
 
 
Q