[翻译] 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

  1. Download files in background threads 在子线程中下载文件
  2. Blocks or delegate style 支持block以及代理的方式
  3. Pause and resume a download 支持断点续传
  4. Set a maximum number of concurrent downloads 可以设置最大并发下载数目
  5. Custom download path 自定义下载路径
  6. Download speed and remaining time 可以查看到下载速度以及下载剩下的时间
  7. Download cancellation 支持取消下载
  8. 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

  1. Drag and drop TCBlobDownload.xcodeproj from Finder to your opened project. 将TCBlobDownload.xcodeproj拖到你的项目当中去.
  2. Project's Target -> Build Phases -> Target Dependencies -> add TCBlobDownload. Then, click Link binary with libraries and add libTCBlobDownload.a (no worries if it's red).  Project's Target -> Build Phases -> Target Dependencies ->中添加TCBlobDownload,然后,点击Link binary with libraries 添加上libTCBlobDownload.a静态库(如果是红色的也不用紧张).  
  3. Go to build settings, switch "always search user paths" to YES and add$(PROJECT_TEMP_DIR)/../UninstalledProducts/include to "User Header Search Paths". 到build settings中,将"always search user paths"切换到YES,然后添加$(PROJECT_TEMP_DIR)/../UninstalledProducts/include到"User Header Search Paths"
  4. Project's Target -> Build Settings -> Other Linker Flags -> Add -ObjC  Target -> Build Settings -> Other Linker Flags ->添加上-Objc
  5. 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 from TCBlobDownloader. 你可以设置下载依赖,使用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
时间: 2024-08-31 11:39:32

[翻译] TCBlobDownload的相关文章

[翻译]JDK 8 兼容性指南

翻译官方文档,删除部分可忽略. 译者:坤谷,井桐,激酶 兼容性是一个复杂的问题. 本文介绍了Java平台潜在的三种不兼容问题: 源码: 源码兼容性问题关注Java源代码转换成class文件是否兼容,包括代码是否仍然可编译. 二进制: 在Java语言规范中,二进制兼容性定义为:"类的改变是二进制兼容的(或者不破坏二进制兼容性),是指如果改变前的类的二进制在链接时没有错误,那么改变后的类在链接时仍然没有错误." 行为 : 行为兼容性包括在运行时执行的代码的语义. 欲了解更多信息,请参阅Op

java.security.Guard翻译

  Overview Package  Class Use Tree Deprecated Index Help JavaTM 2 PlatformStd. Ed. v1.4.2  PREV CLASS   NEXT CLASSFRAMES    NO FRAMES     All Classes SUMMARY: NESTED | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD java.security Interface Gua

翻译CFSSL相关操作文档

我发现国内这个CFSSL资料蛮少的. 但如果深入到K8S认证之后,这块知识又必不可少. (OPENSSL也可实现,但好像不是主流) 于是花了两天快速翻译了一下几个文档. 贡献给有需要的同仁. 如有错误(肯定有!),欢迎提正. 百度网盘共享地址: https://pan.baidu.com/s/1skAQtAH

如何这段C#代码翻译成VB代码?谢谢!

问题描述 如何这段C#代码翻译成VB代码?谢谢! private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { //自动点击弹出确认或弹出提示 IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument; vDocument.parentWindow.execScrip

php-java和PHP有纯中文的官方手册吗?还是只有部分的翻译?

问题描述 java和PHP有纯中文的官方手册吗?还是只有部分的翻译? java和PHP有纯中文的官方手册吗?还是只有部分的翻译?我英文不好,能不能学呢? 解决方案 http://cn2.php.net/manual/zh/index.php 解决方案二: java的JDK有中文版的API,PHP网上也有中文手册.现在网络资源这么丰富,只有肯上心,学东西还是很容易的. 选定一个完整的视频教程,跟着练习,上手是很容易的. 我就是2010年暑假跟着传智播客视频教程自学的Java,现在已经很熟练了.祝好

傲游浏览器怎么翻译网页

  步骤一:没有傲游浏览器的童鞋 步骤二:点开下拉====勾选"翻译". 步骤三:输入你想要的翻译的网址,选定你想翻译的内容 步骤四:耐心等待翻译结果

Word 2010中的“翻译字典”

  1.打开一篇文字文档,并且里面与你有需要翻译的文字,例如,我们这里先选择一篇中文散文; 2.在功能区点击"审阅"选项卡,选择"语言"区域的"翻译"选项组,单击"翻译所选文字"; 3.单击"审阅"功能卡,点击"语言"区域的"翻译"选项组,在弹出的下拉菜单中选择"选择转换语言"; 4.此时窗口会弹出一个"翻译语言选项"的对话框,

Word每一页的左边显示英语右边显示中文翻译

  现在,您想实现的效果是,在每一页里面,左边是英文,右边是对应的翻译好的中文.像这样的排版方式,可以方便我们更好的学习英语. ①使用分栏的是不科学的 要解决这个问题,很多人第一时间就会想到分栏,想把英文放在栏的左边,中文放在栏的右边.然而,这是可行的,却是不科学的. 因为,使用Word里面的自动分栏,原文英文和翻译后的中文,很难一一对应,造成学习上的困难.另外,如果您想再排版实现一一对应,那么,难度是非常大. ②使用文本框也是不合理的 以上方法难以实现.很多人会想到使用文本框的办法. 即在Wo

360浏览器如何翻译英文网页

  整个网页翻译: 1.打开360浏览器,在浏览器中打开你想浏览的英文网站,选择浏览器上面的翻译三角符号. 2.选择第一项,翻译当前网页,就会开始翻译了. 3.翻译完后,就可以看到全部是中文了. 单个句子翻译: 1.同样选择浏览器上面的翻译,选择第二项翻译文字. 2.在弹出的翻译对话框中,将要翻译的英文复制到文本框中,点击下面的翻译. 3.翻译完后,翻译的结果就在下面了,很方便的.