2

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?

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389

2 Answers2

4

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);
        } 
    });
}];
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
Ryan Kreager
  • 3,571
  • 1
  • 20
  • 35
  • it worked, but now I'm getting the following error: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempted to find non-existent uuid 1DF77D29-3FCD-4657-BC24-9AB0BF89C987' any suggestions on that one? (it crashes the app!) – Can Poyrazoğlu Dec 16 '14 at 12:29
  • Are you querying for UUIDs as part of the query? – Ryan Kreager Dec 16 '14 at 16:06
  • Nope, I didnt even know Parse objects had uuids until I saw this error today :) – Can Poyrazoğlu Dec 16 '14 at 18:35
  • By the way, after starting to use local cache, app sometimes started to log me out (i was logged in with Facebook) randomly when I opened the app. After these random logouts, I get this error when I tap login with Facebook again. – Can Poyrazoğlu Dec 16 '14 at 18:36
  • 1
    Regarding your logout problem, add a new question here on SO and I'd be happy to take a look. (I don't want to answer a separate problem in the comments since it makes it harder for others to find the solution!) – Ryan Kreager Dec 18 '14 at 14:09
  • You are right, it deserves its own question. I just need to nail it down. (I've currently disabled pinning as it's extremely buggy in every other aspect and the logout problem seems to have gone away though) – Can Poyrazoğlu Dec 18 '14 at 14:10
  • Good plan. I'm holding off on using the iOS local datastore until I see less bug questions here on SO :) – Ryan Kreager Dec 18 '14 at 14:19
  • Exactly, local datastore is a great idea but the implementation is just too buggy for prime time yet. I have a feed-based app and I was going to use it for caching for app start (for loading previous feed immediately while refresing in background) and I ended up adding a category to `PFObject` with `NSCoding` support to save/reload between sessions. It's hacky/a little buggy, but works perfectly :) – Can Poyrazoğlu Dec 18 '14 at 14:21
0

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

For your reference :

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

soulshined
  • 9,612
  • 5
  • 44
  • 79
  • obviously. if you read my question and the link that you've pasted, you'd see that the patterns are the same. – Can Poyrazoğlu Dec 12 '14 at 01:59
  • it may be related to this though: http://stackoverflow.com/questions/27435725/enabling-local-data-store-on-parse-by-calling-enablelocaldatastore-before-initia – Can Poyrazoğlu Dec 12 '14 at 02:05
  • if your not getting that same error then you have a different issue: have you tried implementing the code they suggested? [[query findInBackground] continueWithBlock:^id(BFTask *task) { } – soulshined Dec 12 '14 at 02:06
  • have you logged your objects array for pinning here : [PFObject pinAllInBackground] and made sure its not nil? – soulshined Dec 12 '14 at 02:09
  • yeah, there are 50 objects in the array. – Can Poyrazoğlu Dec 12 '14 at 02:12
  • so try setting a match whereKey: equalTo: just to see if will return objects then, if not you might have a bug i'm not sure from this point of view. – soulshined Dec 12 '14 at 02:15
  • I've updated the question. It appears to be a problem with pinning in the first place. – Can Poyrazoğlu Dec 12 '14 at 15:23
  • @CanPoyrazoğlu I am a Parse user and love helping people fix their Parse issues, unfortunately i have not had enough time to review their new SDK beyond the blog they posted. I would suggest offering a bounty to attract more opportunities for successful answer. It's a shame they don't have an active moderator to answer these questions like that have in the past – soulshined Dec 12 '14 at 22:13
  • Yeah, all big companies should have at least one person regularly watching SO tags about them every several hours. I'll offer a bounty once the question is eligible if I still haven't found the solution. – Can Poyrazoğlu Dec 12 '14 at 22:14