[翻译] 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之间,大部分都是视频文件.
Ive 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 Documentation Installation Examples Roadmap
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 dont 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 Projects Target - Build Settings - Other Linker Flags)
如果你没有CocoaPods,你可以用这个here
Import as a static library
Drag and drop TCBlobDownload.xcodeproj from Finder to your opened project. 将TCBlobDownload.xcodeproj拖到你的项目当中去. Projects Target - Build Phases - Target Dependencies - add TCBlobDownload. Then, click Link binary with libraries and add libTCBlobDownload.a (no worries if its red). Projects Target - Build Phases - Target Dependencies - 中添加TCBlobDownload,然后,点击Link binary with libraries 添加上libTCBlobDownload.a静态库(如果是红色的也不用紧张). 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" Projects 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 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[翻译]IAdaptable是什么? IAdaptable在Eclipse里是一个非常重要的接口。对于Eclipse开发老手来说,它就像异常处理和抽象类一样寻常;但是对新手而言,它却令人感到困惑和畏惧。这篇文章将向你解释IAdaptable到底是什么,以及它在Eclipse里起到的作用。
相关文章
- IDEA(Jetbrains系列,pycharm,goland…)翻译插件推荐Translation 安装和使用以及快捷键绑定…
- 【翻译】持续交付 VS 持续部署
- 【翻译】测试替身
- 杭电子科技大学_god ls a girl神翻译
- 一秒钟教你成功使用Chrome谷歌浏览器的网页翻译,亲测好用!
- 【最新】Google Translate不再向中国区域提供翻译服务
- 解决Chrome 浏览器翻译提示错误:无法翻译此页面问题
- 【Android应用开发】RecycleView API 翻译 (文档翻译)
- 再胜OpenAI!谷歌发布20亿参数通用模型,100多种语言自动识别翻译
- 【翻译】下一步:Go 泛型
- MySQL:Unlock the Power of Database Translations(mysql外文翻译)
- 微软宣布更新微软翻译应用增加9种新语言支持 总支持语言提升至83种
- 继华为后,小米开始内测小爱同学 AI 字幕:实时翻译外语原声视频和直播
- 硬核观察 | IBM 教会 AI 翻译编程语言
- SQL Server技术拓展:打造无可匹敌的数据库管理系统(sqlserver 翻译)
- 时空壶,用 AI 翻译耳机连接世界
- 《Linkerd官方文档》翻译邀请
- SixSix翻译的XAML教程语法简介
- asp.netGoogle的translate工具翻译API