PFQuery pinAllInBackground:block: never completes

2019-02-20 02:04发布

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?

2条回答
可以哭但决不认输i
2楼-- · 2019-02-20 02:33

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);
        } 
    });
}];
查看更多
\"骚年 ilove
3楼-- · 2019-02-20 02:46

Have you looked at their Docs on how to query local datastore :

For your reference :

https://parse.com/docs/ios_guide#localdatastore-find/iOS

查看更多
登录 后发表回答