我在这件事上迷失了方向,只是想不通。
我的应用程序有一个文本字段和一个按钮,您可以提交您的电话号码或只是一个数字(没关系)。
按钮方法是这样的
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 个匹配项,并且两个用户都输入了相同的数字(您可以在上面的代码中看到我为我的问题输入了 **)。如何使用 Current PFUser 和我在 Objects 中找到的新用户创建关系代码?我想在他们两个用户 ID 之间创建一个关系,并将其作为 Friends 类放在解析的数据库中。顺便提一句。上面的代码正在运行,我创建了两个用户并为他们两个都输入了 1234 并且它的工作:D - 现在我剩下的就是连接他们两个用户。
非常感谢你们!.