pizzafilms
pizzafilms

Reputation: 4019

PFQuery findObjectsInBackgroundWithBlock does not return

I copied the example for a PFQuery right out of the docs, put my field and class names in it, but it never hits the completionBlock.

- (void) loadMyWindows { 
    PFQuery *query = [PFQuery queryWithClassName:@"RGWindow"];
    [query whereKey:@"creatorID" equalTo:me.facebookID];

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

        // it never gets here...

        if (!error) {
            NSLog(@"Successfully retrieved %d objects.", objects.count);
        for (PFObject *object in objects) {
            NSLog(@"%@", object.objectId);
        }

        [self gotoMain];
    } else {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];

I've double checked many times...there are several RGWindow objects in the Data Browser, they have a "creatorID" field, and their ACL's say Public Read.

I'm stumped.

Upvotes: 0

Views: 815

Answers (2)

pizzafilms
pizzafilms

Reputation: 4019

As it turns out, my PFObject subclass had an init method which is not allowed, an obviously caused havoc in this random place. Maybe I should have read the docs more.

Upvotes: 0

Ryan Kreager
Ryan Kreager

Reputation: 3581

I finally found the solution: make SURE that all your objects are instantiated before attempting a call. If you have anything null, it hangs prior to the query and block - it just flat out stops running the code for that particular query. For example:

NSLog(@"test1");
PFQuery *dailyChallengesQuery = [GrowthChallenges query];
NSLog(@"test2");
[dailyChallengesQuery whereKey:kParse_GrowthChallengesGrowthRole equalTo:currentRole];
//When currentVirtue = nil, THIS JUST HANGS - nothing below here is called properly
[dailyChallengesQuery whereKey:kParse_GrowthChallengesGrowthVirtue equalTo:currentVirtue];
NSLog(@"test3");
[dailyChallengesQuery getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) {
    NSLog(@"test4");
    currentChallenge = (GrowthChallenges *)object;
    [self setupTableView];
}];

When currentVirtue is nil, it logs:
test1
test2

However, when currentVirtue is set properly, it logs:
test1
test2
test3
test4

Check your me.facebookID variable to be sure it is non-nil prior to setting up your query.

Upvotes: 1

Related Questions