Giter VIP home page Giter VIP logo

Comments (8)

Danie1s avatar Danie1s commented on August 11, 2024

这个已经是总进度,你可以对比单个任务的大小和总任务的大小

from tiercel.

ripperhe avatar ripperhe commented on August 11, 2024

@Danie1s 好的,我又验证了一次,确实是,不好意思哈。 非常感谢 👍 👍 👍

from tiercel.

ripperhe avatar ripperhe commented on August 11, 2024

@Danie1s
朋友,我现在有个需求,就是我有很多组批量任务(每组任务里面有多个文件需要下载),每一组都要有一个独立的文件夹存储数据,同时每一组都有一个总进度,多组任务可能同时进行;

总体来看,我每一组任务都创建一个 TRManager 来管理,就可以符合这个需求了。

不过现在的问题是,想要后台下载,根据你文档中的提示,必须在 appdelegate 写以下代码

// 必须实现此方法,并且把identifier对应的completionHandler保存起来
    func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
        let downloadManagers = [TRManager.default, downloadManager2, downloadManager3, downloadManager4]
        downloadManagers.forEach { (manager) in
            if identifier == manager.identifier {
                manager.completionHandler = completionHandler
            }
        }

    }

可是 app 启动的时候根本不知道到底有多少组任务,只有用户触发了,才开启下载;所以现在看来是不是没有办法解决?

from tiercel.

Danie1s avatar Danie1s commented on August 11, 2024

你这个需求确实不好实现,我想到两种办法。

  1. 把多个文件压缩成一个包,这样一组就等于一个文件
  2. 把任务信息持久化到沙盒,App启动的时候就去读这个信息,从而创建对应数量的TRManager

from tiercel.

ripperhe avatar ripperhe commented on August 11, 2024

其实我们公司之前就是把文件搞成zip包一起下载的,后来因为一些问题故意拆开的。

所以我选择第2种方案,那么我只需要记录一下每一个正在下载manager的identifier就可以了,然后启动的时候直接根据identifier创建,对吧?

from tiercel.

Danie1s avatar Danie1s commented on August 11, 2024

给AppDelegate添加一个managers数组,用户触发下载的时候,创建manager,同时添加到managers数组,把identifier保存到沙盒的文件里

在didFinishLaunchingWithOptions方法读沙盒的文件,根据identifier创建manager,同时添加到managers数组,在handleEventsForBackgroundURLSession里就可以拿到对应的manager。

from tiercel.

ripperhe avatar ripperhe commented on August 11, 2024

哥们儿,我按照你说的方式做了,目前看来下载文件是可行的,没有问题

不过现在有个新的问题,就是调用批量下载方法,当文件达到一百多个的时候,也就是 URLStrings 里面有一百多个的时候,这个方法会阻塞主线

downloadManager?.multiDownload(URLStrings)

并且进度回调也不对了,从 Log 中可以看到,进度第一次回调的时候 已经是总进度0.5以上,然后接着总进度的回调又变成了0.3,0.4 等,总之不对(按理说应该越来越大)

image

以上结果我是用你的这个Demo 测试的,只是修改了 ViewController3.swiftURLStrings,然后得到这样的结果

不过这100多个文件加起来一共40多m,也就意味着每个文件都比较小,所以下载很快,是不是因为这个问题导致回调进度不对呢?

from tiercel.

Danie1s avatar Danie1s commented on August 11, 2024

加我QQ联系:176516837

from tiercel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.