SuperMarcus / NineAnimator

An elegant way of discovering anime on iOS.
https://9ani.app
GNU General Public License v3.0
809 stars 100 forks source link

[BUG] Queued Episodes do not start downloading in background #173

Closed uttiya10 closed 4 years ago

uttiya10 commented 4 years ago

Describe the bug NineAnimator only downloads 2 episodes at a time, and queues any other episodes. When the app is in the background, the queued episodes will never start downloading.

To Reproduce Replace this with the steps to reproduce the behavior:

  1. Start downloading more then 2 episodes (AnimeHub with Fserver is very fast for testing)
  2. Turn off the screen
  3. Wait until you think all episodes are finished downloading.
  4. Turn on the screen and open the app.

Expected behavior All episodes have finished downloading

Actual behavior First two episodes finish downloading, while the queued episodes will only start upon app entering foreground.

Device:

Additional context Mustard is disgusting.

SuperMarcus commented 4 years ago

This is not a bug. The download system is designed in such a way that no additional downloading tasks will be initiated when the app is in the background. That's why we recommend people to leave the app open when they've queued multiple downloads so that the app can take care of the queued episodes at its discretion.

The reason why the download system is like this is that the URL loading system limits the ability for apps to schedule downloads consecutively. See the Use Background Sessions Efficiently section of the Downloading Files in the Background if you want all the details. But, in short, Apple delays the downloading tasks that are scheduled right after a download completion call, which means our download system won't work reliably if we try to schedule downloads in such ways.

Now I haven't done much research about how the system calculates the delay for consecutively scheduled tasks. It may not be as big of a deal as I thought. If you want to do some experiments, then, by all means, go ahead. I'd be interested to see the results as well.