[翻译] TCBlobDownload
TCBlobDownload

TCBlobDownload uses NSOperations to download large files (typically videos, music... well: BLOBs) using NSURLConnection in background threads.
TCBlobDownload使用了NSOpreations来下载大文件(尤其是视频,音乐之类的),在子线程中用NSURLConnection作为下载用的类.
Tested with files from ~150MB to ~1.2GB, mostly videos.
本人测试过的下载文件大小介于150Mb到1.2G之间,大部分都是视频文件.
I've implemented TCBlobDownloader which extends NSOperation and useTCBlobDownloadManager to execute it. You can set a delegate or use blocks for each download to update your views etc…
我已经实现了TCBlobDownloader,它扩展了NSOperation,你可以用TCBlobDownloadManager来运行它.你可以设置一个代理或者是一个block来更新下载进度.
Requires iOS 5.0 or later and ARC.
需要iOS5.0+以及ARC
Features
- Download files in background threads 在子线程中下载文件
- Blocks or delegate style 支持block以及代理的方式
- Pause and resume a download 支持断点续传
- Set a maximum number of concurrent downloads 可以设置最大并发下载数目
- Custom download path 自定义下载路径
- Download speed and remaining time 可以查看到下载速度以及下载剩下的时间
- Download cancellation 支持取消下载
- Download dependencies 支持队列下载
Documentation
Browse the documentation on Cocoadocs or add it directly to Xcode by downloading the docset and placing it into ~/Library/Developer/Shared/Documentation/DocSets/. (or use Dash)
你可以通过Cocoadocs来下载支持文档,或者是你直接下载好后放在~/Libaray/Developer/Shared/Documentation/DocSets/.下面(或者直接使用Dash)
Installation
CocoaPods
Add the following to your Podfile and run $ pod install:
你可以直接使用CocoaPods来安装,执行 $ pod install 即可:
pod 'TCBlobDownload'
If you don't have CocoaPods installed or integrated into your project, you can learn how to do so here.
(Also be sure the $(inherited) flag is set in your Project's Target -> Build Settings -> Other Linker Flags)
如果你没有CocoaPods,你可以用这个here
Import as a static library
- Drag and drop
TCBlobDownload.xcodeprojfrom Finder to your opened project. 将TCBlobDownload.xcodeproj拖到你的项目当中去. - Project's Target -> Build Phases -> Target Dependencies -> add
TCBlobDownload. Then, click Link binary with libraries and addlibTCBlobDownload.a(no worries if it's red). Project's Target -> Build Phases -> Target Dependencies ->中添加TCBlobDownload,然后,点击Link binary with libraries 添加上libTCBlobDownload.a静态库(如果是红色的也不用紧张). - Go to build settings, switch "always search user paths" to
YESand add$(PROJECT_TEMP_DIR)/../UninstalledProducts/includeto "User Header Search Paths". 到build settings中,将"always search user paths"切换到YES,然后添加$(PROJECT_TEMP_DIR)/../UninstalledProducts/include到"User Header Search Paths" - Project's Target -> Build Settings -> Other Linker Flags -> Add
-ObjC Target -> Build Settings -> Other Linker Flags ->添加上-Objc - Import the lib. (no worries if no autocomplete) 导入静态库
#import <TCBlobDownload/TCBlobDownload.h>
Examples
1. Blocks
To immediately start a download in the default TCBlobDownloadManager directory (tmp/ by default):
你可以用block的方式来开始一个默认的下载任务(直接下载到tmp/目录下):
TCBlobDownloadManager *sharedManager = [TCBlobDownloadManager sharedInstance]; TCBlobDownloader *downloader = [sharedManager startDownloadWithURL:@"http://give.me/abigfile.avi"
downloadPath:nil
firstResponse:^(NSURLResponse *response) { }
progress:^(uint64_t receivedLength, uint64_t totalLength, NSInteger remainingTime, float progress) {
// downloader.remainingTime
// downloader.speedRate
}
error:^(NSError *error) { }
complete:^(BOOL downloadFinished, NSString *pathToFile) { }];
If you set a custom path:
你也可以自己设置路径:
NSString *customPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"My/Custom/Path/"]; TCBlobDownloader *downloader = [sharedManager startDownloadWithURL:@"http://give.me/abigfile.avi"
customPath:customPath // here we set the path
andDelegate:nil];
This will create the given path if needed and download the file in the Path/ directory. Please note that during the download process you have no control over the file name as explained with reasons why in the documentation. Remember that you should follow the iOS Data Storage Guidelines.
这将会根据你给出的路径来创建出下载文件.请注意,下载期间你无法控制文件命名,你可以看看苹果的文件存储规范.
2. Delegate
You can either set a delegate which can implement those optional methods if delegates have your preference over blocks:
你也可是设置代理来控制下载:
- (void)download:(TCBlobDownloader *)download didReceiveFirstResponse:(NSURLResponse *)response
{ } - (void)download:(TCBlobDownloader *)download didReceiveData:(uint64_t)received onTotal:(uint64_t)total
{
// download.remainingTime
// download.speedRate
} - (void)download:(TCBlobDownloader *)download didStopWithError:(NSError *)error
{ } - (void)download:(TCBlobDownloader *)download didFinishWithSucces:(BOOL)downloadFinished atPath:(NSString *)pathToFile
{ }
3. Other features
If a download has been stopped and the local file has not been deleted, when you will restart the download to the same local path, the download will start where it has stopped using the HTTPRange header (14.35). 如果你已经停止了下载,而且,本地的文件也没有被删除掉,下一次下载会直接从断点处下载.
You can also set dependencies in your downloads using the
addDependentDownload:method fromTCBlobDownloader. 你可以设置下载依赖,使用addDependentDownload:来设置下载依赖问题.
See documentation for more details.
请看文档来了解更多的信息.
Roadmap
If you have any idea or request, please suggest it!
如果你有任何建议或者需求,提出来吧!
- Multi segmented downloads 多线程下载同一个文件.
- Dash XML feed for documentation versioning
[翻译] TCBlobDownload的更多相关文章
- 《Django By Example》第五章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者@ucag注:大家好,我是新来的翻译, ...
- 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...
- [翻译]开发文档:android Bitmap的高效使用
内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...
- 【探索】机器指令翻译成 JavaScript
前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...
- 《Django By Example》第三章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:第三章滚烫出炉,大家请不要吐槽文中 ...
- 《Django By Example》第二章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:翻译完第一章后,发现翻译第二章的速 ...
- 《Django By Example》第一章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:本人目前在杭州某家互联网公司工作, ...
- 【翻译】Awesome R资源大全中文版来了,全球最火的R工具包一网打尽,超过300+工具,还在等什么?
0.前言 虽然很早就知道R被微软收购,也很早知道R在统计分析处理方面很强大,开始一直没有行动过...直到 直到12月初在微软技术大会,看到我软的工程师演示R的使用,我就震惊了,然后最近在网上到处了解和 ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点
在这一章中,我们将学习如何使用基架快速搭建和运行一个简单的Microsoft ASP.NET MVC Web站点.在我们马上投入学习和编码之前,我们首先了解一些有关ASP.NET MVC和Entity ...
随机推荐
- golang笔记(1)-数据库查询结果映射至结构体
通用的映射模式 query:="select id,name from user where id=?" //单个结构体ret:=&Activity{} DbClient( ...
- Java虚拟机(二):JVM内存模型
所有的Java开发人员可能会遇到这样的困惑?我该为堆内存设置多大空间呢?OutOfMemoryError的异常到底涉及到运行时数据的哪块区域?该怎么解决呢?其实如果你经常解决服务器性能问题,那么这些问 ...
- C#中的Dictionary类,默认key是区分大小写的
在C#中定义一个Dictionary Dictionary<string,string> dictionary = new Dictionary<string,string>( ...
- [笔记] Python 中JSON数据的读写
前言 JSON(JavaScript Object Notation,JavaScript对象表示法)是一种轻量级的数据交换语言 JSON是独立于语言的文本格式, JSON 数据格式与语言无关 JSO ...
- 用ruby调用执行shell命令
碰到需要调用操作系统shell命令的时候,Ruby为我们提供了六种完成任务的方法: 1.Exec方法: Kernel#exec方法通过调用指定的命令取代当前进程: 例子: $ ...
- *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<WKWebViewConfiguration 0x1701bcd20> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the k
问题描述: ionic项目,windows下正常,打包android可正常运行: 因为需要打包到iPhone (ios 11.0.1)上测试,将代码拿到Mac OS环境下(重新npm install. ...
- Python import搜索的路径顺序
在程序中导入时,如下顺序 1.Python 标准库模块2.Python 第三方模块3.应用程序自定义模块 import的搜索顺序: 首先判断这个module是不是built-in即内建模块,如果是 ...
- 【学习笔记】--- 老男孩学Python,day9, 文件操作
有 + 就是有光标,注意光标位置 不同模式打开文件的完全列表: http://www.runoob.com/python/python-files-io.html 模式 描述 r 以只读方式打开文件 ...
- 【学习笔记】--- 老男孩学Python,day18 面向对象------继承
继承 继承是一种创建新类的方式,在python中,新建的类可以继承一个或多个父类, 父类又可称为基类或超类,新建的类称为派生类或子类 python中类的继承分为:单继承和多继承 class Fathe ...
- Django之WSGI浅谈
一.什么是Web框架 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统. 浏览器与服务器之间发起HTTP请求: 1.浏览器发送一 ...