LCDownloadManageriOS 下載助手
一個(gè)簡(jiǎn)單易用的下載助手?;贏FN,實(shí)現(xiàn)斷點(diǎn)續(xù)傳,采取Block方式回調(diào)下載進(jìn)度、文件大小、下載是否完成等。
-
引入方法:
- 方法一:CocoaPods引入:
pod 'LCDownloadManager' - 方法二:把LCDownloadManager文件夾(在Demo中)拖到你的項(xiàng)目中。
- 方法一:CocoaPods引入:
-
在相應(yīng)位置導(dǎo)入頭文件:
#import "LCDownloadManager.h"。 -
調(diào)用下面的方法即可:
// 當(dāng)前下載任務(wù)
AFHTTPRequestOperation *operation1 = nil;
// 下載(提供了類(lèi)方法和實(shí)例方法,根據(jù)使用習(xí)慣調(diào)用)
operation1 = [LCDownloadManager downloadFileWithURLString:@"http://mw2.dwstatic.com/2/8/1528/133366-99-1436362095.mp4" cachePath:@"demo1.mp4" progress:^(CGFloat progress, CGFloat totalMBRead, CGFloat totalMBExpectedToRead) {
// totalMBRead 和 totalMBExpectedToRead 單位是MB
NSLog(@"Task1 -> progress: %.2f -> download: %fMB -> all: %fMB", progress, totalMBRead, totalMBExpectedToRead);
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Task1 -> Download finish");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (error.code == -999) NSLog(@"Task1 -> Maybe you pause download.");
NSLog(@"Task1 -> %@", error);
}];
// 暫停(提供了類(lèi)方法和實(shí)例方法,根據(jù)使用習(xí)慣調(diào)用)
[LCDownloadManager pauseWithOperation:operation1];
- 在
Info.plist中添加NSAppTransportSecurity,類(lèi)型Dictionary - 在
NSAppTransportSecurity下添加NSAllowsArbitraryLoads,類(lèi)型Boolean,值設(shè)為YES
評(píng)論
圖片
表情
