Uploading large amount of data using background upload task

Hello,
I’m trying to upload the user’s entire photo library to a server so this can mean thousands of files.

To achieve this task I'm trying to use a background URLSessionConfiguration with the following steps:
  1. Fetch all the phassetid

  2. For each phassetid, export the asset to my container

  3. Create a file upload task using the background session

However I read some post on the forum which discourage using a background session for this kind of task (Moving to Fewer, Larger Transfers) and according to this post BackgroundTasks could be a better fit.

I also noticed that it looks like I’m hitting some kind of rate limiter. Even with the app in the foreground, the transfers stop reporting progress after some time and then start reporting again after a small amount of time. This doesn't happen with a normal URLSessionConfiguration.

So I was wondering if it was indeed the way to go or if there was some better/other way to do it ?



Answered by DTS Engineer in 664956022

I tried using background NSURLSession in the foreground but it looks
like the rate limiter is still somehow active.

Back in the iOS 8 timeframe (IIRC this was discussed in WWDC 2014 Session 707 “What’s New in Foundation Networking” [1]) we set things up so that bringing your app to the foreground would boost the priority of any NSURLSession background session work that it’s doing. I haven’t researched this in detail in a long time, but anecdotal evidence suggests that this is no longer the case )-: If you’d like to see this behaviour back again, I recommend filing a bug along those lines.

Share and Enjoy

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

[1] No link because this video is not longer available )-:
The best solution here is to fix your server so that you don’t have to make thousands of small transfers. If that’s not feasible then your options aren’t great:
  • You can live with the limits imposed by the NSURLSession background session.

  • You can use a BGProcessingTaskRequest, which allows you to use a standard session (albeit at the cost of a significant delay between you making the request and you actually getting background time).

You can also use various hybrid approaches.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
The hybrid way seems to be a decent approach.

I tried using background NSURLSession in the foreground but it looks like the rate limiter is still somehow active.
There is a thread about this bug and someone advises to use normal session when possible. As the thread is a year old, is it still a good solution ?
Accepted Answer

I tried using background NSURLSession in the foreground but it looks
like the rate limiter is still somehow active.

Back in the iOS 8 timeframe (IIRC this was discussed in WWDC 2014 Session 707 “What’s New in Foundation Networking” [1]) we set things up so that bringing your app to the foreground would boost the priority of any NSURLSession background session work that it’s doing. I haven’t researched this in detail in a long time, but anecdotal evidence suggests that this is no longer the case )-: If you’d like to see this behaviour back again, I recommend filing a bug along those lines.

Share and Enjoy

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

[1] No link because this video is not longer available )-:
Thank you for those answers they are very helpful 😊
We are working on a cloud base fileprovider app and we were expecting a lot (maybe too much) from this API. I will fill a bug report and in the meantime we will refactor our code to use default session whenever possible to upload / download files.
Uploading large amount of data using background upload task
 
 
Q