Search code examples
iosparse-platformpfquerypfobject

PFQuery pinAllInBackground:block: never completes


I have a Parse app and I want to enable local data store for caching/offline use. In my app delegate, I've set [Parse enableLocalDatastore];.

In my query (to the server), I'm making a normal query, but I'm pinning the results upon fetch:

[followingsQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    [PFObject pinAllInBackground:objects block:^(BOOL succeeded, NSError *error) {
        NSLog(@"er: %@", error);
    }];
    ... //rest of my handler
}];

However, the completion block (NSLog(@"er: %@", error);) is never called. Not even with an error. I've got breakpoints everywhere. pinAllInBackground:block: is called, but it's completion handler is never called (my app's been running for 2 minutes straight, it's pinning only 100 objects, so it should be instantaneous). I've also tried pinAllInBackground:withName:block: but no difference. I've tried pinAll: and it just never returns, blocking the calling thread (it doesn't consume any CPU though). How can I solve this problem?


Solution

  • This is a known bug that I have experienced when running a nested inBackground-type method inside another inBackground-type method in Parse. The current workaround is to use a different dispatch method, such as Grand Central Dispatch.

    Try this:

    [followingsQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSError *error = nil;
            id result = [PFObject pinAll:objects error:&error];
            if (error) {
                NSLog("error: %@", error);
            } 
        });
    }];