Upload on background and updating live activities

Hello everyone, I'm developing a new feature that allows the user to keep track of a background upload through live activities.

Im using the URLSessionTaskDelegate to keep track of the task progress and it works fine when the app is in foreground, but when the app goes to background, it stop after a few seconds. The upload still continues and Im able to receive updates on it's completion through the application(_ application: UIApplication, handleEventsForBackgroundURLSession but only through that.

Also when I put the app back to foreground it updates to the correct progress so this is only happening in background.

This is the URLSessionConfiguration I'm using:

let config = URLSessionConfiguration.background(withIdentifier: "\(uploadBackgroundTaskIdentifier)")

config.isDiscretionary = false
config.allowsCellularAccess = true
config.shouldUseExtendedBackgroundIdleMode = true
config.sessionSendsLaunchEvents = true
config.timeoutIntervalForResource = 28800

Does anyone knows how should I be able to keep track of the progress even when the app is in background?

Does anyone knows how should I be able to keep track of the progress even when the app is in background?

When you use a URLSession background session, the work is actually being done by a system process (currently nsurlsessiond) on your behalf. If the user moves your app to the background then, unless something else is keeping your app running, it’ll be suspended. After that it may even be terminated. Once the transfer is completed, the system resumes (or relaunch) your app in the background.

This resume happens on completion, and for various other events like authentication challenges. However, it does not happen for progress event.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

For those following along at home, I’ll be helping Yuri Frota in a different context.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Were you able to figure this out? I’m trying to build the same behavior in my app. I saw that WeTransfer was also able to do it all locally. Thanks!

Upload on background and updating live activities
 
 
Q