I want to download and process a image from Firebase to local directory on secondary thread and then update the UI. The problem is firebase returns in completion on main thread and not on the thread on which my NSOperation is being executed. I want to switch back to the thread on which my NSOperation is working. Is there a way I can achieve it ?
- Download Meta Data from Firebase Realtime DB
- Process and Store in Local Db
- Update UI
- Download image From Firebase to temp location
- Once properly downloaded move to appropriate Directory
- Update UI
Below is the sample code and have mentioned thread on which the completion is called.
[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.
}];
}];
}];