neekeetab / CachingPlayerItem

Play and cache media content simultaneously on your iOS device
MIT License
520 stars 89 forks source link

Downloading audio in background #8

Closed yeralin closed 6 years ago

yeralin commented 6 years ago

I noticed that if I start downloading an audio file using CachingPlayerItem, and then lock my phone, the session will be terminated.

I tried to quickly fix it by modifying: let configuration = URLSessionConfiguration.default to let configuration = URLSessionConfiguration.background(withIdentifier: "bgSessionConfiguration")

But it didn't work. Seems like it is not that simple, you need to write a handler, and stuff.

Do you know any quick way to download audio in background?

neekeetab commented 6 years ago

You need to ask the system for the execution in the background. https://developer.apple.com/documentation/uikit/uiapplication/1623031-beginbackgroundtask

yeralin commented 6 years ago

@neekeetab Apparently, dataTask does not support background downloads. Only downloadTask is allowed