iOS实现大文件下载功能:TCBlobDownload

jopen 11年前

实现大文件下载功能,可以在后台线程(background threads)进行文件下载,不会给前台线程操作造成影响。支持暂停和重新恢复下载。作者测试过150MB ~ 1.2GB之间的大文件下载。
代码图2是App在下载文件时,在Xcode输出框的输出文字。
具体功能特色如下:
1. 在后台线程下载大文件;
2. 使用 blocks 或者 delegate 模式;
3. 可以暂停和重新恢复下载;
4. 可以设置能够下载的最大文件的大小;
5. 下载过程中可以取消下载,并且删除掉已经下载的部分文件;

- (TCBlobDownload *)startDownloadWithURL:(NSURL *)url                  downloadPath:(NSString *)customPathOrNil                   andDelegate:(id<TCBlobDownloadDelegate>)delegateOrNil;    - (TCBlobDownload *)startDownloadWithURL:(NSURL *)url                  downloadPath:(NSString *)customPathOrNil                 firstResponse:(void (^)(NSURLResponse *response))firstResponseBlock                      progress:(void (^)(float receivedLength, float totalLength))progressBlock                         error:(void (^)(NSError *error))errorBlock                      complete:(void (^)(BOOL downloadFinished, NSString *pathToFile))completeBlock;    - (void)startDownload:(TCBlobDownload *)blobDownload;    - (void)setDefaultDownloadDirectory:(NSString *)pathToDL;    - (void)setMaxConcurrentDownloads:(NSInteger)max;    - (NSUInteger)downloadCount;    - (void)cancelAllDownloadsAndRemoveFiles:(BOOL)remove;
- (id)initWithUrl:(NSURL *)url       downloadPath:(NSString *)pathToDL // cannot be nil        andDelegate:(id<TCBlobDownloadDelegate>)delegateOrNil;    - (id)initWithUrl:(NSURL *)url       downloadPath:(NSString *)pathToDL // cannot be nil      firstResponse:(void (^)(NSURLResponse *response))firstResponseBlock           progress:(void (^)(float receivedLength, float totalLength))progressBlock              error:(void (^)(NSError *error))errorBlock           complete:(void (^)(BOOL downloadFinished, NSString *pathToFile))completeBlock;    - (void)cancelDownloadAndRemoveFile:(BOOL)remove;    - (void)addDependentDownload:(TCBlobDownload *)blobDownload

iOS实现大文件下载功能:TCBlobDownload iOS实现大文件下载功能:TCBlobDownload

项目主页:http://www.open-open.com/lib/view/home/1385603365015