- (void)downLoad{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//2.创建请求对象
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://img.zcool.cn/community/018d4e554967920000019ae9df1533.jpg@900w_1l_2o_100sh.jpg"]];
//3.创建下载请求任务
/*
*第一个参数: 请求对象
*第二个参数:progress 进度回调
*第三个参数:destination 需要在该回调中告诉方法应该把下载的文件保存带哪里
targetPath:临时存放路径(默认写入的)
response:响应头信息
*第四个参数:completionHandler 完成后调用
*/
NSURLSessionDownloadTask*downloadTask = [manager downloadTaskWithRequest:requestprogress:^(NSProgress*_NonnulldownloadProgress) { NSLog(@"%f",1.0*downloadProgress.completedUnitCount/downloadProgress.totalUnitCount);
}destination:^NSURL*_Nonnull(NSURL*_NonnulltargetPath,NSURLResponse*_Nonnullresponse) {
NSString *fullPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingString:response.suggestedFilename]; return[NSURL fileURLWithPath:fullPath];
}completionHandler:^(NSURLResponse*_Nonnullresponse,NSURL*_NullablefilePath,NSError*_Nullableerror) {
NSLog(@"%@",filePath);
}];
//4.执行任务
[downloadTaskresume];
}