您的位置:首页 > 大数据 > 人工智能

XXXX must be used from main thread only

2018-01-23 16:35 267 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐