0
因此,我的应用程序加载到用户的联系人中并存储了他们的电话号码,但我想查询这些电话号码与存储在Parse中的电话号码,以确定他们的联系人是否正在使用该应用程序。通过解析查询多个值
所以,我知道如何通过每个电话号码都作为一个单一的查询使用类似的内部for循环下面的代码工作,
NSString *phoneNumber = CFBridgingRelease(ABMultiValueCopyValueAtIndex(phoneNumbers, i));
//parse query for any matches to the phone number
PFQuery *query = [PFQuery queryWithClassName:@"_User"];
[query whereKey:@"phoneNumber" equalTo:phonenumberfieldfriend.text];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d users.", objects.count);
// Do something with the found objects
if (objects.count == 0) {
//uialert letting the user know that no phone number matches the query
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No User"
message:@"No user matches this phone number"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
phonenumberfieldfriend.text = @"";
}
//if there is only one number matching the query
if (objects.count ==1) {
for (PFObject *object in objects) {
NSLog(@"%@", objects);
usernamefriend =[ object objectForKey:@"username"];
numberfriend = [object objectForKey:@"phoneNumber"];
firstnamefriend = [object objectForKey:@"firstName"];
lastnamefriend = [object objectForKey:@"lastName"];
emailfriend = [object objectForKey:@"email"];
add.hidden=true;
phonenumberfieldfriend.hidden=true;
confirmuser.hidden=false;
NSLog(@"one user entered %@",usernamefriend);
}
}
//if there is more than one phonenumber matching the query as
//the user to input the friends username
//instead
if (objects.count>1) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"More than one user!"
message:@"More than one user with this number please enter a username instead!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[email protected]"Please enter a username";
add.hidden=true;
adduser.hidden=false;
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];}
,但我想知道是否有可能搜索所有联系人的电话号码与单个查询?
所以返回的第一个结果,你的说法,而不是做了替换(PFObject *在对象的对象),你只是想使用'findObjectsInBackgroundWithBlock'来一次查找所有它们? – soulshined 2015-03-02 17:00:27
是的,我想搜索该人的联系人的每个电话号码,并在该类中找到他们匹配的用户_user – David 2015-03-02 17:03:57
因此,您的问题不是查询它从设备联系人应用程序中检索电话号码,并检查用户中是否有一个类? – soulshined 2015-03-02 17:06:21