Parse: is it possible to track PFObject download progress

I have a PFObject containing text and a PFFile.

PFObject *post = [PFObject objectWithClassName:@"Posts"];
post[@"description"] = self.Photodescription.text;
NSData *picture =  UIImageJPEGRepresentation(self.capturedPicture, 0.5f);
post[@"picture"] = [PFFile fileWithName:@"thumbnailPicture.png" data:picture];

I would like to get the download progress in order to display the progression bar. The following function only works for PFFile.

[post[@"picture"] saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    }progressBlock:^(int percentDone) {
        // Update your progress spinner here. percentDone will be between 0 and 100.
        NSLog(@"%i", percentDone);
    }];

Is there a way to do the same for PFObject?

0
source share
1 answer

array ? PFObject . PFObjects PFObjects , saveAlInBackground:, , chunkSize ( PFObjects ) , , :

+(void)saveAllInBackground:(NSArray *)array chunkSize:(int)chunkSize block:(PFBooleanResultBlock)block progressBlock:(PFProgressBlock)progressBlock
{
    unsigned long numberOfCyclesRequired = array.count/chunkSize;
    __block unsigned long count = 0;
    [PFObject saveAllInBackground:array chunkSize:chunkSize block:block trigger:^(BOOL trig) {
        count++;
        progressBlock((int)(100.0*count/numberOfCyclesRequired));
    }];
}

+(void)saveAllInBackground:(NSArray *)array chunkSize:(int)chunkSize block:(PFBooleanResultBlock)block trigger:(void(^)(BOOL trig))trigger
{

    NSRange range = NSMakeRange(0, array.count <= chunkSize ? array.count:chunkSize);
    NSArray *saveArray = [array subarrayWithRange:range];
    NSArray *nextArray = nil;
    if (range.length<array.count) nextArray = [array subarrayWithRange:NSMakeRange(range.length, array.count-range.length)];
    [PFObject saveAllInBackground:saveArray block:^(BOOL succeeded, NSError *error) {
        if(!error && succeeded && nextArray){
            trigger(true);
            [PFObject saveAllInBackground:nextArray chunkSize:chunkSize block:block trigger:trigger];
        }
        else
        {
            trigger(true);
            block(succeeded,error);   
        }
    }];
}
+2

All Articles