先来讲讲怎么下载,afn3.0以后确实改变了许多,我就不多说了直接上代码了。
-(void)textANF3{
//1.创建管理者对象
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//2.确定请求的URL地址
NSURL *url = [NSURL URLWithString:@"http://114.55.34.110:8888/huabao/prods/pdf/Reader.pdf"];
//3.创建请求对象
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//4.下载任务
NSURLSessionDownloadTask *task = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
//打印下下载进度
NSLog(@"打印下下载进度:%lf",1.0 * downloadProgress.completedUnitCount / downloadProgress.totalUnitCount);
} destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
//设置下载路径,并将文件写入沙盒,最后返回NSURL对象
NSString *fullPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:response.suggestedFilename];
NSLog(@"targetPath:%@",targetPath);
NSLog(@"fullPath:%@----%@",fullPath,[NSURL fileURLWithPath:fullPath]);
return [NSURL fileURLWithPath:fullPath];
} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
NSLog(@"完成:%@--%@",response,filePath);
NSHTTPURLResponse *response1 = (NSHTTPURLResponse *)response;
NSInteger statusCode = [response1 statusCode];
if (statusCode == 200) {
//
}else{
//
}
}];
//5.开始启动下载任务
[task resume];
}