A long-running Parse operation is being executed on the main thread

后端 未结 4 1319
甜味超标
甜味超标 2020-11-30 07:27

I am getting the error:

\"A long-running Parse operation is being executed on the main thread. Break on warnParseOperationOnMainThread() to debug.\"

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 08:10

    Maybe it is a bit late, but here you go. I think the problem come from the fact that you are trying to get to objects fetch at the same time:

    [[PFUser currentUser] objectId];
    

    and:

     [query getObjectInBackgroundWithId...];
    

    It will be better to get the userId first, such as:

    //First fetch and store the id in a string so you can reuse it whenever you want
    NSString *userId = [PFUser currentUser].objectId; 
    

    Second:

      // Do your second fetch here:          
      PFQuery *query = [PFQuery queryWithClassName:@"User"];        
    
     [query getObjectInBackgroundWithId:userId block:^(PFObject *object, NSError *error) {
    
     self.firstName = object[@"firstname"];
     self.lastName = object[@"lastname"];
    
     self.nameLabel.text = [[NSArray arrayWithObjects:self.firstName, self.lastName, nil]    componentsJoinedByString:@" "];
     }];
    

    Et voila!

提交回复
热议问题