gpt4 book ai didi

objective-c - 如何从地址簿中获取电话号码作为字符串?

转载 作者:搜寻专家 更新时间:2023-10-30 19:51:31 25 4
gpt4 key购买 nike

我有一个包含联系人姓名的文本字段,我想获取该联系人的电话号码:

ABAddressBookRef adressBook = ABAddressBookCreate();

NSArray *people = (NSArray *)ABAddressBookCopyPeopleWithName(adressBook,
CFStringCreateCopy(kCFAllocatorDefault,
(CFStringRef)recipient));

if((people != nil) && ([people count] == 1)){
ABMultiValueRef person = (ABMultiValueRef)[people objectAtIndex:0];
NSString *phone = (NSString *)ABRecordCopyValue(person,
kABPersonPhoneProperty) ;
NSLog(@"%@", phone);
}

我想要电话号码作为字符串,但这给了我更多:

ABMultiValueRef 0x339470 with 1 value(s)
0: _$!<Mobile>!$_ (0x338c50) - 0177 1647788 (0x339450)

如何只获取字符串形式的数字?

最佳答案

NSMutableArray *phoneNumbers = [[[NSMutableArray alloc] init] autorelease];
ABMultiValueRef multiPhones = ABRecordCopyValue(person,kABPersonPhoneProperty);
for(CFIndex i=0;i<ABMultiValueGetCount(multiPhones);++i) {
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(multiPhones, i);
NSString *phoneNumber = (NSString *) phoneNumberRef;

[phoneNumbers addObject:phoneNumber];
}

关于objective-c - 如何从地址簿中获取电话号码作为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5618635/

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