我在Parse中保存PFRelation时遇到问题。我有一个消息PFObject,并希望将其添加到PFUser类中的PFRelation receivedMessages。代码如下。一切都在努力创造关系。我已将用户对象设置为正常,NSLog显示正确的用户但显示 [sendtoUser saveInBackgroundWithBlock:^(BOOL成功,NSError *错误)根本没有被调用为"关系已保存&# 34;未在控制台中显示。有人可以帮忙吗?感谢
PFObject *message = [PFObject objectWithClassName:@“message”];
message[@“fromUser"]=[PFUser currentUser].username;
message[@“message"]=@"喵!";
message[@“read"]=@NO;
[message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
NSLog(@“message saved”);
PFQuery *usernameQuery = [PFUser query];
[usernameQuery whereKey:@"username" equalTo:[[self.friends objectAtIndex:index] username]];
[usernameQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
PFUser *sendtoUser = (PFUser *)objects[0];
NSLog(@"send to user: %@", sendtoUser.username); //this works
PFRelation *receivedMessages = [sendtoUser relationForKey:@"receivedMessages”];
[receivedMessages addObject:message];
[sendtoUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
NSLog(@“relation saved”); //this doesn’t display at all
}];//end save user relation block
}];//end username query block
}];//end save message block, this works