【发布时间】:2017-10-27 08:36:44
【问题描述】:
我想将图像从 Firebase 下载并处理到辅助线程上的本地目录,然后更新 UI。问题是 firebase 在主线程上完成返回,而不是在执行我的 NSOperation 的线程上。我想切换回我的 NSOperation 正在运行的线程。有没有办法可以实现它?
- 从 Firebase 实时数据库下载元数据
- 在本地数据库中处理和存储
- 更新用户界面
- 将图片从 Firebase 下载到临时位置
- 正确下载后移动到适当的目录
- 更新用户界面
下面是示例代码,并提到了调用完成的线程。
[photosDetailReferenceDB observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
//Main Thread
[self.downloadQueue addOperationWithBlock:^{
//Bg Thread 2
[[[FirebaseHelper sharedManager].storageuserRef child:serverPath] writeToFile:[NSURL fileURLWithPath:tempPath] completion:^(NSURL * _Nullable URL, NSError * _Nullable error) {
//Main Thread
// Here I want to switch back to Thread 2.
// Since yet I have to move the image back to proper directory and update the image status in core data.
}];
}];
}];
【问题讨论】:
标签: ios objective-c firebase nsoperationqueue