gpt4 book ai didi

ios - 以编程方式获取手机号码

转载 作者:行者123 更新时间:2023-11-28 20:11:11 25 4
gpt4 key购买 nike

我正在 iOS 中开发应用程序。我可以检索人的名字和姓氏,但我想要的是如何检索手机号码信息。我已经有了这段代码来获取名字和姓氏。

CFErrorRef error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);

if (addressBook != nil) {
NSLog(@"Succesful.");


NSArray *allContacts = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);


NSUInteger i = 0; for (i = 0; i < [allContacts count]; i++)
{

ABRecordRef contactPerson = (__bridge ABRecordRef)allContacts[i];


firstName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson,kABPersonFirstNameProperty);
lastName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson, kABPersonLastNameProperty);


fullName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];


} else {

NSLog(@"Error Reading Address Book");
}

最佳答案

您可以使用以下代码获取所有电话条目。我还指定了几种电话类型,以便您了解如何处理该问题。

ABMultiValueRef phoneNumbers = ABRecordCopyValue(contactPerson, kABPersonPhoneProperty);

for (CFIndex i=0; i < ABMultiValueGetCount(phoneNumbers); i++)
{
NSString* phoneLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phoneNumbers, i);
NSString* phoneNumber = ABMultiValueCopyValueAtIndex(phoneNumbers, i);

if([phoneLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel])
{

}
else if([phoneLabel isEqualToString:(NSString *)kABPersonPhoneIPhoneLabel])
{

}

CFRelease(phoneNumber);
CFRelease(phoneLabel);
}

CFRelease(phoneNumbers);

关于ios - 以编程方式获取手机号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20189091/

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