我有每个人的姓名和电子邮件,我想根据这两个变量检索人的手机号码。我不想检索每个人的手机号码(连同姓名和电子邮件)。仅针对用户点击的那个。我怎样才能做到这一点?
问问题
827 次
1 回答
1
使用此代码根据名字和电子邮件 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);
于 2013-06-13T06:33:54.170 回答