AFNetworking 3.0 下载PDF文件

1、创建网络下载对象 

AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];

2、 设置下载地址 

NSURL *url = [NSURL URLWithString:self.responseModel.pdf_url];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

NSString *filePath = [NSString setPathOfDocumentsByFileName:[NSString stringWithFormat:@"%@",@"Invoice"]];

NSLog(@"%@",filePath);

3、开始请求下载 

NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {

} destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {

/* 设定下载到的位置 */

NSString *savePath = [filePath stringByAppendingPathComponent:response.suggestedFilename];

NSLog(@"======%@",savePath);

return [NSURL fileURLWithPath:savePath];

} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {

  //下载完成之后的操作

[self downloadSuccessWithFilePath:filePath];

}];

[downloadTask resume];

}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容