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;
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;
相关文章推荐
- Error: CompareBaseObjectsInternal can only be called from the main thread
- "may only be called from the main thread"
- Unity3d报告奇怪的错误CompareBaseObjectsInternal can only be called from the main thread.
- Unity3d报奇怪的错误CompareBaseObjectsInternal can only be called from the main thread.
- Error: CompareBaseObjectsInternal can only be called from the main thread
- -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.【创建键盘监听事件,然后操作键盘(弹出、收回),结果在运行程序时出现如下错误(如有知道解决办法的朋友请留言探讨!)】
- unity报“GetLocalizedString can only be called from the main thread.”错误。
- unity报错get_streamingAssetsPath can only be called from the main thread. Constructors and field initi
- 安卓开发异常rx.exceptions.OnErrorNotImplementedException: Must be called from main thread of fragment host
- Unity3d报奇怪的错误CompareBaseObjectsInternal can only be called from the main thread.
- unity DestroyBuffer can only be called from the main thread
- Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be
- you are calling a UIKit method that can only be invoked from the UI thread.
- Exception in thread "main" java.sql.SQLException: Connections could not be acquired from the underly
- exception in thread main org.apache.spark.sparkexception:A master URL must be set in your
- Python SQLite3的问题sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in th
- exception in thread main org.apache.spark.sparkexception:A master URL must be set in your
- java.lang.IllegalStateException: Hardware acceleration can only be used with a single UI thread.
- PhoneFactory.getDefaultPhone must be called from Looper thread
- 出错:PhoneFactory.getDefaultPhone must be called from Looper thread