NSURLSessionDownloadTask *task = [[AFHTTPSessionManager manager] downloadTaskWithRequest:request progress:^(NSProgress *downloadProgress) {
downloadView.observedProgress = downloadProgress;
} destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
return [NSURL fileURLWithPath:fullPath];
} completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
if(error){
NSLog(@"Error: %@", error);
}else{
NSLog(@"success ");
}
}];
[task resume];
[uiProgressView setProgressWithDownloadProgressOfTask:task animated:YES];
downloadTaskWithRequest 第一个参数 request 是文件的线上路径
第二个参数 progress 上传进度
第三个参数destination返回储存沙盒的路径
第四个参数completionHandler下载结束的结果
其中downloadView.observedProgress = downloadProgress; 会报错
例如:
点开“?”出现
主要原因是此处的 downloadProgress 是多个线程异步返回的进度数据 赋值是不允许这样
所以要在第二个参数返回值加上
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
}];
把赋值的代码写在里面
[[NSOperationQueue mainQueue] addOperationWithBlock:^{//只留下主线程返回的进度数据
downloadView.observedProgress = downloadProgress;
}];