1

First off, I'm on iOS 13.6.1

I'm downloading HLS videos to later play offline. It all works as expected when in foreground, all the logic does what it should and there doesn't seem to be any problem.
But when the app goes to background I stop getting updates for the AVAggregateAssetDownloadTask (I mean, I don't see the logs in the delegate callbacks printing in the Xcode console).

I followed the documentation:

  • NSURLSessionConfiguration sessionSendsLaunchEvents is set to true
  • The AppDelegate implements handleEventsForBackgroundURLSession
  • The Session delegate implements URLSessionDidFinishEventsForBackgroundURLSession

Also, I have background modes enabled for fetch.

The crazy thing is, if I hook up the instruments network monitor, I do get all the updates. And I see that the download keeps going in the background. Even without the changes mentioned in the documentation indicated above, I still see that the download keeps going in the background with the monitor open.
But it seems that the network monitor keeps the app alive somehow, because if I don't open it, then I get zero updates.

To be clear, I'm not even thinking about downloads starting or finishing in the background, and waking the app or anything of that. I just want to start a download, go to the background and have the download keep downloading stuff and notifying me (which AFAIK is done in a separate process, and I can confirm from the network monitor it is).

An example:

  • open the app
  • start a download
  • go to background
  • no updates are shown
  • open the instruments network monitor and connect to the app running in the device
  • suddenly start getting updates

I'm running out of ideas. Nothing makes sense anymore, short of a bug in the framework.
Any sort of idea will be greatly appreciated, no matter how simple it may appear.
Thanks in advance!

PS: when going to settings>storage I sometimes see that the file size grows while in the background, which would mean that the download is continuing even if I don't see updates from the delegate callbacks. At some points I saw the file size unchanged over a period of background time, but that might have been an unrelated thing (I hope).

Andres C
  • 463
  • 6
  • 26

0 Answers0