XXXX must be used from main thread only

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;  

      }];




             downloadView . observedProgress  = downloadProgress;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值