如何从地址簿中获取电话号码作为字符串? [英] How to get phone number from address book as string?
本文介绍了如何从地址簿中获取电话号码作为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有联系人姓名的文本字段,我想获取该电话号码:
I have a text field with a contact name and I want to get the phone number for that:
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);
}
我希望电话号码为字符串,但这给了我更多: / p>
I want the phone number as string but this gives me a lot more:
ABMultiValueRef 0x339470 with 1 value(s)
0: _$!<Mobile>!$_ (0x338c50) - 0177 1647788 (0x339450)
如何将数字作为字符串?
How to I get just the number as string?
推荐答案
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];
}
这篇关于如何从地址簿中获取电话号码作为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文