gpt4 book ai didi

ios - Parse.com 查看好友 请求重复 iOS

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:01:10 28 4
gpt4 key购买 nike

我想避免与 Parse.comCloud CodeiOS Code重复。这是我在数据库中的类(class): Screenshot

我希望当“from”userId 已经发送到“to”userId 时,不会发送第二个 friendRequest。

这是我的 iOS 代码:

PFUser *selectedUser = [self.allUsers objectAtIndex:indexPath.row];
//request them
PFObject *friendRequest = [PFObject objectWithClassName:@"FriendRequest"];
friendRequest[@"from"] = self.currentUser;
friendRequest[@"fromUsername"] = [[PFUser currentUser] objectForKey:@"username"];
//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:@"Sent !" message:@"Friend request sent" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];



} else {

// error occurred
}
}];

最佳答案

您好,如果您已经发送了好友请求或从“CurrentUser”到“SelectedUser”,您可以按照以下步骤获取:

-(void)fetchfriendrequestAndSave{

PFUser *selectedUser = [self.allUsers objectAtIndex:indexPath.row];
//request them
PFObject *friendRequest = [PFObject objectWithClassName:@"FriendRequest"];
friendRequest[@"from"] = self.currentUser;
friendRequest[@"fromUsername"] = [[PFUser currentUser] objectForKey:@"username"];
//selected user is the user at the cell that was selected
friendRequest[@"to"] = selectedUser;
// set the initial status to pending
friendRequest[@"status"] = @"pending";

PFQuery*query = [PFQuery queryWithClassName:@"FriendRequest"];
[query whereKey:@"from" equalTo:self.currentuser];
[query whereKey:@"to" equalTo: selectedUser];
[query findObjectsInBackgroundWithBlock:^(NSArray*FriendRequestArray, NSError*error){

if(!error){

NSArray*temp = [NSArray arrayWithArray:object];
if(temp.count==0){

//Save & Send Request

[friendRequest saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {


if (succeeded) {


UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sent !" message:@"Friend request sent" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];



} else {

// error occurred
}
}];


}else{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"FriendREquest ERROR" message:@"Friend Request is Already Submitted" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];


}


}else{

}

}];
}

通过PFQuery:

您搜索“CurrentUser”和“SelectedUser”的值是否在 Parse.com 服务的同一行中可用!如果是,它将返回一个数组“temp”...如果不是,它也会返回一个数组...但是如果它为 0,我们将计算这个数组(所以这意味着它里面没有值,简而言之...... .没有好友请求

if (NSArray*temp.count == 0) 保存请求!

希望对您有所帮助!对我来说它有效

关于ios - Parse.com 查看好友 请求重复 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30213837/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com