源码简介:一个简单易用的的下载助手。依赖于AFN,实现断点续传,采取Block方式回调下载进度、文件大小、下载是否完成等。
源码截图:
代码片段:
- // 当前下载任务
- AFHTTPRequestOperation *operation = nil;
- // 下载
- operation = [LCDownloadManager downloadFileWithURLString:@"http://mw2.dwstatic.com/2/8/1528/133366-99-1436362095.mp4" cachePath:@"demo2.mp4" progressBlock:^(CGFloat progress, CGFloat totalMBRead, CGFloat totalMBExpectedToRead) {
- // totalMBRead 和 totalMBExpectedToRead 单位是MB
- NSLog(@"%f %f %f", progress, totalBytesRead, totalBytesExpectedToRead);
- } successBlock:^(AFHTTPRequestOperation *operation, id responseObject) {
- NSLog(@"Download finish");
- } failureBlock:^(AFHTTPRequestOperation *operation, NSError *error) {
- if (error.code == -999) NSLog(@"Maybe you pause download.");
- NSLog(@"%@", error);
- }];
- // 暂停
- [[LCDownloadManager pauseWithOperation:operation];];