解析朋友请求代码将不起作用

时间:2015-07-24 03:21:33

标签: objective-c parse-platform

我已经编写了一些代码,因此一个用户可以向其他用户发送朋友请求,这可以被接受或拒绝。

当您查看他们的个人资料并按“发送好友请求”按钮时,会执行以下操作:

PFQuery *query = [PFUser query];
[query whereKey:@"objectId" equalTo:self.userID];
PFUser *selectedUser = (PFUser *)[query getFirstObject];

PFUser *currentUser = [PFUser currentUser];
//request them
PFObject *friendRequest = [PFObject objectWithClassName:@"_User"];
friendRequest[@"from"] = currentUser;
//selected user is the user at the cell that was selected
friendRequest[@"to"] = selectedUser;
// set the initial status to pending
friendRequest[@"status"] = @"pending";
[friendRequest saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (succeeded) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Yay" message:@"Friend request sent" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else {
        NSLog(@"Error");
    }
}];

但我收到此错误:[Error]: Caught "NSInternalInconsistencyException" with reason "User cannot be saved unless they are already signed up. Call signUp first."

事情是两个用户已经明显注册了......我很困惑。欢呼声。

1 个答案:

答案 0 :(得分:0)

您需要通过执行以下操作注册(这也将保存用户)用户:

user.signUpInBackgroundWithBlock { (success, error) -> Void in
            print("signup");
}

您不需要user.saveInBackgroundWithBlock