Skip to content

Instantly share code, notes, and snippets.

@igiu1988
Last active August 29, 2015 13:57
Show Gist options
  • Save igiu1988/9481931 to your computer and use it in GitHub Desktop.
Save igiu1988/9481931 to your computer and use it in GitHub Desktop.
// controller.m 调用下载接口.类方法
[YJDownloadManager goTodownload];
// YJDownloadManager.m
+ (void)goTodownload
{
// code .....
[[TCBlobDownloadManager sharedInstance] setMaxConcurrentDownloads:1];
for (NSString *urlKey in urlDic.allKeys) {
// 下载该url,下载到Documents/offlineMedia/[courseId]
// TODO: 使用第三方库做队列code
NSURL *url = [NSURL URLWithString:urlKey];
NSString *path = [NSFileManager directoryPath:[NSString stringWithFormat:@"offlineMedia/%@", courseId]];
[[TCBlobDownloadManager sharedInstance] startDownloadWithURL:url customPath:path firstResponse:^(NSURLResponse *response) {
NSURL *requestUrl = [response URL ];
NSLog(@"%@", requestUrl.lastPathComponent);
} progress:^(float receivedLength, float totalLength, NSInteger remainingTime) {
NSLog(@"receivedLength %f, totalLength %f", receivedLength, totalLength);
} error:^(NSError *error) {
NSLog(@"下载出错:%@", [error localizedDescription]);
} complete:^(BOOL downloadFinished, NSString *pathToFile) {
if (downloadFinished) {
NSLog(@"%@下载完成", pathToFile);
}else{
[[NSFileManager defaultManager] removeItemAtPath:pathToFile error:nil];
}
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment