6 Star 15 Fork 5

Danie1s / Tiercel

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Version Platform Language SPM Support License

Tiercel 是一个简单易用、功能丰富的纯 Swift 下载框架,支持原生级别后台下载,拥有强大的任务管理功能,可以满足下载类 APP 的大部分需求。

如果你使用的开发语言是 Objective-C ,可以使用 TiercelObjCBridge 进行桥接

Tiercel 3.0

Tiercel 3.0 大幅提高了性能,拥有更完善的错误处理,提供了更多方便的 API。从 Tiercel 2.0 升级到 Tiercel 3.0 是很简单的,强烈推荐所有开发者都进行升级,具体请查看 Tiercel 3.0 迁移指南

特性

  • 支持原生级别的后台下载
  • 支持离线断点续传,App 无论 crash 还是被手动 Kill 都可以恢复下载
  • 拥有精细的任务管理,每个下载任务都可以单独操作和管理
  • 支持创建多个下载模块,每个模块互不影响
  • 每个下载模块拥有单独的管理者,可以对总任务进行操作和管理
  • 支持批量操作
  • 内置了下载速度、剩余时间等常见的下载信息
  • 支持自定义日志
  • 支持下载任务排序
  • 链式语法调用
  • 支持控制下载任务的最大并发数
  • 支持文件校验
  • 线程安全

环境要求

  • iOS 10.0+
  • Xcode 11.0+
  • Swift 5.0+

安装

CocoaPods

Tiercel 支持 CocoaPods 集成,首先需要使用以下命令安装 CocoaPod:

$ gem install cocoapods

Podfile文件中

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Tiercel'
end

最后运行命令

$ pod install

Swift Package Manager

从 Xcode 11 开始,集成了 Swift Package Manager,使用起来非常方便。Tiercel 也支持通过 Swift Package Manager 集成。

在 Xcode 的菜单栏中选择 File > Swift Packages > Add Pacakage Dependency,然后在搜索栏输入

git@github.com:Danie1s/Tiercel.git,即可完成集成

手动集成

Tiercel 也支持手动集成,只需把本项目文件夹中的Tiercel文件夹拖进需要集成的项目即可

Demo

打开本项目文件夹中 Tiercel.xcodeproj ,可以直接运行 Demo

用法

基本用法

一行代码开启下载

// 创建下载任务并且开启下载,同时返回可选类型的DownloadTask实例,如果url无效,则返回nil
let task = sessionManager.download("http://dldir1.qq.com/qqfile/QQforMac/QQ_V4.2.4.dmg")

// 批量创建下载任务并且开启下载,返回有效url对应的任务数组,urls需要跟fileNames一一对应
let tasks = sessionManager.multiDownload(URLStrings)

可以对任务设置状态回调

let task = sessionManager.download("http://dldir1.qq.com/qqfile/QQforMac/QQ_V4.2.4.dmg")

task?.progress(onMainQueue: true) { (task) in
    let progress = task.progress.fractionCompleted
    print("下载中, 进度:\(progress)")
}.success { (task) in
    print("下载完成")
}.failure { (task) in
    print("下载失败")
}

可以通过 URL 对下载任务进行操作,也可以直接操作下载任务

let URLString = "http://dldir1.qq.com/qqfile/QQforMac/QQ_V4.2.4.dmg"

// 通过 URL 对下载任务进行操作
sessionManager.start(URLString)
sessionManager.suspend(URLString)
sessionManager.cancel(URLString)
sessionManager.remove(URLString, completely: false)

// 直接对下载任务进行操作
sessionManager.start(task)
sessionManager.suspend(task)
sessionManager.cancel(task)
sessionManager.remove(task, completely: false)

后台下载

从 Tiercel 2.0 开始支持原生的后台下载,只要使用 Tiercel 开启了下载任务:

  • 手动 Kill App,任务会暂停,重启 App 后可以恢复进度,继续下载
  • 只要不是手动 Kill App,任务都会一直在下载,例如:
    • App 退回后台
    • App 崩溃或者被系统关闭
    • 重启手机

如果想了解后台下载的细节和注意事项,可以查看:iOS 原生级别后台下载详解

文件校验

Tiercel 提供了文件校验功能,可以根据需要添加,校验结果在回调的task.validation


let task = sessionManager.download("http://dldir1.qq.com/qqfile/QQforMac/QQ_V4.2.4.dmg")
// 回调闭包可以选择是否在主线程上执行
task?.validateFile(code: "9e2a3650530b563da297c9246acaad5c",
                   type: .md5,
                   onMainQueue: true)
                   { (task) in
    if task.validation == .correct {
        // 文件正确
    } else {
        // 文件错误
    }
}

更多

有关 Tiercel 3.0 的详细使用方法和升级迁移,请查看 Wiki

License

Tiercel is available under the MIT license. See the LICENSE file for more info.

Copyright (c) 2018 176516837@qq.com <176516837@qq.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

简单易用且功能丰富的纯Swift下载框架 展开 收起
Swift 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Swift
1
https://gitee.com/Danie1s/Tiercel.git
git@gitee.com:Danie1s/Tiercel.git
Danie1s
Tiercel
Tiercel
master

搜索帮助