Download several files in background (iOS 7 only)

2020-06-23 14:00发布

问题:

I'm currently developing a podcast application which will run only on iOS 7, and it has a feature that allows to synchronize and download recent episodes in background mode.

So it's clear with Synchronization, I implemented the application:performFetchWithCompletionHandler method and call the sync method in it, and when the sync is done I call completionHandler with UIBackgroundFetchResultNewData, or if it fails I call UIBackgroundFetchResultFailed. But when I run the download manager to start downloading all new episodes it can takes very long, depends on the network quality and file sizes, and the background mode just freezes in some point and suspend the recent download.

How the background downloading should be designed correctly?

Or maybe some link to tutorial which describes properly about the downloading files on background.

回答1:

I'm observing the same behavior when downloading a lot of files.

It looks like it performs better, when you add all the downloads tasks to the background session when your app gets suspended, than to add a new download task every time one has finished and calls your delegate.

An other option would be to use the NewsstandKit. The background download runs very smooth but you have some restrictions like the 24h threshold and your app will be hidden in the newsstand.