我对这一个失去了理智,只是无法理解。
我的应用程序有一个文本字段和一个按钮,您可以提交您的电话号码或只是一个数字(没关系)。
按钮方法是这个
PFObject *addValues= [PFObject objectWithClassName:@"phoneNumber"];
[addValues setObject:phoneNumbers forKey:@"numbers"];
[addValues setObject:whoIsTheUser forKey:@"theUser"];
[addValues saveInBackground];
然后我添加另一个按钮,检查一个不同的用户是否在第一个用户的框中输入了相同的数字,所以我正在为此运行查询,代码就在这里:
PFQuery* numQuery = [PFQuery queryWithClassName:@"phoneNumber"];
[numQuery whereKey:@"numbers" equalTo:phoneNumbers];
[numQuery whereKey:@"theUser" notEqualTo:[PFUser currentUser]];
[numQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
if(!error)
{
// send an alert view for data-has-been-sent
UIAlertView *messageForSending = [[UIAlertView alloc]initWithTitle:@"thank you" message:@"the details has been send" delegate:nil cancelButtonTitle:@"okay" otherButtonTitles:nil, nil ];
[messageForSending show];
for(PFObject *numObject in objects) {
// checking how much objects did the query find ...
if (objects.count > 1 ) {
NSLog(@"yay we found %lu objects", (unsigned long)objects.count);
// in the future i will handle those multiply objects somehow :D
}else{
// if there's 1 results i know it's going to show this message
**// HOW CAN I CHECK WHAT'S THE OTHER PFUser ID IS ? AND HOW CAN I MAKE RELATIONSHIP WITH THE CURRENT PFUser ??**
NSLog(@"yup there is a match");
//NSLog(@"checking objects %lu", objects.count);
NSLog(@" object names %@", objects);
// showing alert message for success
UIAlertView *successMessage = [[UIAlertView alloc]initWithTitle:@"THERE IS A MATCH" message:@" we found a match, would u like to talk with him ?" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"yes", nil];
[successMessage show];
}
}
}
else
{
// there's an error so i will show here in the future an UIAleart view for trying again.
NSLog(@" big error !!!");
}
}
];
所以假设有1个匹配,并且两个用户都输了相同的号码(你可以在上面的代码中看到我把**放在我的问题中)。 如何使用当前PFUser和在对象中找到的新用户创建关系代码? 我想在它们之间建立两个用户ID之间的关系,并将其作为Friends类放在解析数据库中。 BTW。上面的代码工作,我创建了两个用户,并为它们输入1234并且它的工作:D - 现在我剩下的就是连接他们两个用户。
非常感谢! 。
答案 0 :(得分:0)
在第二个按钮查询中,添加以下行:
[numQuery includeKey:theUser];
这将确保将用户对象与结果一起提取。然后,您可以使用以下命令获取此用户对象:
PFUser *otherUser = [objects lastObject]; // Assuming there was only 1 user in the result
现在你有两个用户。
然后,要将它们关联起来,您需要在每个用户对象上添加一列与其他用户为朋友的数组,并使用另一个用户的用户对象更新这两个用户对象上的每个列。此列应该是一个指针数组。
但是,更好的方法是为朋友链接使用单独的解析类。我认为人们可以有几个这样的友谊。也许那是你朋友班的用途?