iOS實現大文件下載功能:TCBlobDownload
實現大文件下載功能,可以在后臺線程(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
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!