I'm looking for help with trying to update a progress indicator using the MRProgress framework. I was able to set up the progress indicator, but I have no idea how to calculate and update its progress. I'm using CloudKit and trying to show the progress when saving a CKRecord. Could someone provide me some direction? Thanks in advance!
self.hud = [MRProgressOverlayView showOverlayAddedTo:self.myCollectionView animated:YES];
self.hud.mode = MRProgressOverlayViewModeDeterminateCircular;
self.hud.titleLabelText = @"Uploading...";
// prepare the CKRecord and save it
[self.ckManager saveRecord:[self.ckManager createCKRecordForImage:self.imageDataAddedFromCamera] withCompletionHandler:^(CKRecord *record, NSError *error) {
if (!error && record) {
NSLog(@"INFO: Record saved successfully for recordID: %@", record.recordID.recordName);
// need to get the recordID of the just saved record before adding the CID to the CIDArray
self.imageDataAddedFromCamera.recordID = record.recordID.recordName;
[self.imageLoadManager addCIDForNewUserImage:self.imageDataAddedFromCamera]; // update the model with the new image
// update number of items since array set has increased from new photo taken
self.numberOfItemsInSection = [self.imageLoadManager.imageDataArray count];
//[MRProgressOverlayView dismissAllOverlaysForView:self.view animated:YES];
[self.hud dismiss:YES];
[self.hud removeFromSuperview];
} else {
NSLog(@"ERROR: Error saving record to cloud...%@", error.localizedDescription);
[self alertWithTitle:@"Yikes!" andMessage:@"We encountered an issue trying to upload your photo to the cloud."];
}
}];
Update: Converted cloudkit methods from convenience API to CKOperations in my CKManager class. I can see the progress updating through logging, but I don't see how to get it back to the viewcontroller. If I were to add it to the completion handler, wouldn't that only send it back once everything is completed? Here's my updated code...
CKManager.h - (void)saveRecord:(NSArray *)records withCompletionHandler:(void (^)(NSArray *records))completionHandler;
CKManager.m - (void)saveRecord:(NSArray *)records withCompletionHandler:(void (^)(NSArray *))completionHandler {
NSLog(@"INFO: Entered saveRecord...");
CKModifyRecordsOperation *saveOperation = [[CKModifyRecordsOperation alloc] initWithRecordsToSave:records recordIDsToDelete:nil];
saveOperation.perRecordProgressBlock = ^(CKRecord *record, double progress) {
if (progress <= 1) {
NSLog(@"Save progress is: %f", progress);
}
};
saveOperation.completionBlock = ^ {
NSLog(@"Save operation completed!");
completionHandler(records);
};
[self.publicDatabase addOperation:saveOperation];
}