I have got every person's name and email and I want to retrieve person's mobile number based on these two variables. I don't want to retrieve every person's mobile number(along with name and email). Just for the one on which user taps. How can I achieve that?
Asked
Active
Viewed 834 times
0
-
2[ABPerson Reference](http://developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html#//apple_ref/c/func/ABAddressBookCopyArrayOfAllPeople) & [Address Book Programming Guide for iOS](http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Introduction.html) – DD_ Jun 13 '13 at 05:33
-
I have done all that. Now That I have every person's name and email I should be able to retrieve particular person's mobile number(On which user taps). – Ali Shahid Jun 13 '13 at 06:17
-
You are able to. So what are you waiting for? – QED Jun 13 '13 at 06:22
-
Basically I want to search address book using name and email and retrieve the mobile number of particular person that matches. – Ali Shahid Jun 13 '13 at 06:25
1 Answers
1
Use this code for fetching the specific contact mobile number based on the first name and email id....
NSMutableString *contactNumber = [[NSMutableString alloc] init];
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for(int i=0; i<nPeople; i++)
{
ABRecordRef person=CFArrayGetValueAtIndex(people, i);
NSMutableString *contacName = [[NSMutableString alloc] init];
[contacName stringByAppendingString:@""];
[contacName appendFormat:@"%@", (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty)];
ABMultiValueRef emailInfo = ABRecordCopyValue(person, kABPersonEmailProperty);
CFIndex emailCount = ABMultiValueGetCount(emailInfo);
NSString *emailId;
if(emailCount > 0)
{
emailId = (NSString *)ABMultiValueCopyValueAtIndex(emailInfo, 0);
}
if(([contacName isEqualToString:@"<<contatct name>>"]) && ([emailId isEqualToString:@"<<email id>>"]))
{
[contactNumber appendFormat:@"%@", (NSString *)ABRecordCopyValue(person, kABPersonPhoneMobileLabel)];
break;
}
}
CFRelease(people);
CFRelease(addressBook);
NSLog("contact Mobile number %@", contactNumber);

Bhanu Prakash
- 1,493
- 8
- 20