1

I have this requirement ,

I need to download a playlist of files in the background . each file is a different url in the playlist . The issue i can start download for second file only after the first one is completed .

Do any one have faced this issue before.

  • i'm connecting to a local box which can handle only one request at a single time. The problem im facing where to submit the resumetask for the second one. If i do it the URLSessionDidFinishEventsForBackgroundURLSession its nt getting called if i call it in the didFinishDownloadingToURL the app will not consider it as background download & the thread will be suspended after 30 secs – user3780181 Aug 12 '14 at 01:36
  • I haven't done exhaustive testing, but I've reproduced your behavior, insofar as requests subsequently scheduled in `didFinishDownloadingToURL` did not continue in the background. The only other things I could suggest were (a) create a new background session with a different identifier for the next download; or (b) try queueing up all of the downloads and the setting `HTTPMaximumConnectionsPerHost` on the `NSURLSessionConfiguration` to 1. Obviously, it would be best if you could fix the server to accept concurrent requests (as you'll see better performance that way). – Rob Aug 12 '14 at 05:23
  • What about [setting the number of concurrent downloads per host](http://stackoverflow.com/questions/20888841/set-number-of-concurrent-downloads-with-nsurlsessiondownloadtask) to one for that session, and queueing them all up at the same time? If you add new things in the background, at the end of your didFinishDownloading, there's no guarantee that iOS will prioritise them, as I understand it, as it seems less like a specifically user-triggered action. – Matt Gibson Jul 24 '15 at 11:33

1 Answers1

0

Post a notification and watch for it on the main thread. Simply build your own queue of requests and when the notification is raised, check the queue for remaining requests and fire them off as needed.

john elemans
  • 2,578
  • 2
  • 15
  • 26