Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

疑问:是否可以后台下载任务完成后创建新的后台下载任务 #24

Closed
yixianxueqi opened this issue Jan 30, 2019 · 1 comment

Comments

@yixianxueqi
Copy link

问题1:下载的任务是大量小的且有依赖性的,例:A>B>C>D; 创建后台下载任务A,当A任务在后台完成下载后,是否可以创建新的后台下载任务B? (尝试这样做后发现新的后台下载任务B启动下载的时机不确定,不是立刻而是一段时间后)。
问题2:如果不可以后台下载完成后再创建新的后台任务,那么在前台时需要把所有的后台下载任务先创建出来,上限是多少?

@Danie1s
Copy link
Owner

Danie1s commented Jan 30, 2019

1、可以在后台创建任务,我那篇文章有解释了,在所有任务完成后,会调用代理方法。只要不在前台,isDiscretionary属性就为true,你可以去看官方的说明,这个启动的时机确实被系统管理了。

When the system resumes or relaunches your app, it uses a rate limiter to prevent abuse of background downloads. When your app starts a new download task while in the background, the task doesn't begin until the delay expires. The delay increases each time the system resumes or relaunches your app.

As a result, if your app starts a single background download, gets resumed when the download completes, and then starts a new download, it will greatly increase the delay. Instead, use a small number of background sessions — ideally just one — and use these sessions to start many download tasks at once. This allows the system to perform multiple downloads at once, and resume your app when they have completed.

Keep in mind, though, that each task has its own overhead. If you find you need to launch thousands of download tasks, change your design to perform fewer, larger transfers.

Note

The delay is reset to 0 whenever the user brings your app to the foreground. It also resets if the delay period elapses without the system resuming or relaunching your app.

2、上限我没特地测试,数量应该不少

@Danie1s Danie1s closed this as completed Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants