Ios 解析好友请求处理
我正在parse中进行查询,以检查好友请求。查询返回对象,我可以记录它们。现在,当我将其转换为PFUSER和Ios 解析好友请求处理,ios,objective-c,parse-platform,Ios,Objective C,Parse Platform,我正在parse中进行查询,以检查好友请求。查询返回对象,我可以记录它们。现在,当我将其转换为PFUSER和NSLog时,它会因错误而崩溃:键“FirstName”没有数据。在获取其值之前,请调用fetchIfNeeded。“请在此处帮助我 PFQuery * friendQuery = [PFQuery queryWithClassName:@"friendship"]; [friendQuery whereKey:@"toUser" equalTo:[PFUser currentUser]
NSLog
时,它会因错误而崩溃:键“FirstName”没有数据。在获取其值之前,请调用fetchIfNeeded。“
请在此处帮助我
PFQuery * friendQuery = [PFQuery queryWithClassName:@"friendship"];
[friendQuery whereKey:@"toUser" equalTo:[PFUser currentUser]];
[friendQuery whereKey:@"status" equalTo:@"Pending"];
[friendQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error)
{
//NSLog error
}
else {
NSLog(@"friendRequestCount = %d", objects.count);
PFObject *object=[objects objectAtIndex:0];
NSLog(@"%@", object);
self.friendRequestArray= objects;
NSLog(@"%@",object[@"toUser"]);
PFUser *user1= object[@"toUser"];
NSString *friendName = [NSString stringWithFormat:@"%@ %@",user1[@"FirstName"], user1[@"LastName"] ];
NSLog(@"name= %@",friendName);
}
}];
你可以使用1或2,我有评论下面的代码,而不是测试
PFQuery * friendQuery = [PFQuery queryWithClassName:@"friendship"];
[friendQuery whereKey:@"toUser" equalTo:[PFUser currentUser]];
[friendQuery whereKey:@"status" equalTo:@"Pending"];
//1
[friendQuery includeKey:@"toUser"];
[friendQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error)
{
//NSLog error
}
else {
NSLog(@"friendRequestCount = %d", objects.count);
PFObject *object=[objects objectAtIndex:0];
NSLog(@"%@", object);
self.friendRequestArray= objects;
NSLog(@"%@",object[@"toUser"]);
PFUser *user1= object[@"toUser"];
//2 Change PFUser to PFObject
PFObject *user1 = object[@"toUser"];
[user1 fetchIfNeeded];
NSString *friendName = [NSString stringWithFormat:@"%@ %@",user1[@"FirstName"], user1[@"LastName"] ];
NSLog(@"name= %@",friendName);
}
}];
非常感谢HoanNguyen,这很有效。我用了1.朋友,如果你能帮助我理解,那是什么[friendQuery includeKey:@“toUser”];做我真的不明白。@AbinGeorge如果不使用它,查询中的友谊对象只有一个toUser存根,带有指向用户对象的指针。如果您使用includeKey,那么完整的用户对象将与友谊对象一起返回谢谢你,帅哥和HoanNguyen,现在我明白了