Getting 'This query has an outstanding network connection.'

172 views Asked by At

I'm getting 'This query has an outstanding network connection.'

I know only one query is allowed at time and I think that's what I'm doing here but apparently not..

retrieveFromParse is at viewDidLoad.

-(void) retrieveFromParse{

    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
    [query whereKey:@"photo" equalTo:[PFObject objectWithoutDataWithClassName:@"photoObject" objectId:self.currentObjectID]];
    [query orderByDescending:@"createdAt"];

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
        // The find succeeded.
            NSLog(@"Successfully retrieved %d scores.", (int)objects.count);
            // Do something with the found objects
            for (PFObject *object in objects) {
                NSLog(@"%@", object.objectId);

                self.commentArray = [object objectForKey:@"comment"];
            }
        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];

    // If no objects are loaded in memory, we look to the cache
    // first to fill the table and then subsequently do a query
    // against the network.
    if ([self.objects count] == 0) {
        query.cachePolicy = kPFCachePolicyCacheThenNetwork;
    }
}


- (id)initWithStyle:(UITableViewStyle)style currentObjectID:(NSString*) currentObjectID {
    self = [super initWithStyle:style];
    if (self) {

        self.currentObjectID = currentObjectID;

        self.parseClassName = @"extra";
        self.pullToRefreshEnabled = YES;
        self.paginationEnabled = NO;
        self.objectsPerPage = 25;

    }
    return self;
}
1

There are 1 answers

0
Ryan Kreager On

The problem is here:

if ([self.objects count] == 0) {
    query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}

You're calling that after you make the call in the background. In other words, you are trying to modify a query that is currently being made while it's being made in the background - triggering the error. Try this instead:

-(void) retrieveFromParse{

    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
    [query whereKey:@"photo" equalTo:[PFObject objectWithoutDataWithClassName:@"photoObject" objectId:self.currentObjectID]];
    [query orderByDescending:@"createdAt"];

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
        // The find succeeded.
            NSLog(@"Successfully retrieved %d scores.", (int)objects.count);
            // Do something with the found objects
            for (PFObject *object in objects) {
                NSLog(@"%@", object.objectId);

                self.commentArray = [object objectForKey:@"comment"];
            }
        } else {
            // Log details of the failure
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }

        // If no objects are loaded in memory, we look to the cache
        // first to fill the table and then subsequently do a query
        // against the network.
        if ([self.objects count] == 0) {
            query.cachePolicy = kPFCachePolicyCacheThenNetwork;
        }
    }];
}