gpt4 book ai didi

ios - 如何从通讯录 iOS 中检索手机号码

转载 作者:行者123 更新时间:2023-11-29 03:50:53 27 4
gpt4 key购买 nike

我已经获得了每个人的姓名和电子邮件,并且我想根据这两个变量检索人的手机号码。我不想检索每个人的手机号码(以及姓名和电子邮件)。只针对用户点击的那个。我怎样才能做到这一点?

最佳答案

使用此代码根据名字和电子邮件 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);

关于ios - 如何从通讯录 iOS 中检索手机号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17079801/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com