从地址簿中获取 iPhone 电话号码标签
那么我有一个方法可以从iPhone上的通讯录中获取所有联系人电话号码,但是有没有办法获取电话号码标签呢?例如你可以这样做:
我希望修改打印标签的方法(例如 iPhone/Home/移动/等)。
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef all = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex n = ABAddressBookGetPersonCount(addressBook);
for( int i = 0 ; i < n ; i++ )
{
ABRecordRef ref = CFArrayGetValueAtIndex(all, i);
NSString *firstName = (NSString *)ABRecordCopyValue(ref, kABPersonFirstNameProperty);
NSLog(@"Name %@", firstName);
ABMultiValueRef *phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
{
NSString *phoneLabel = @""; // ???
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);
//CFRelease(phones);
NSString *phoneNumber = (NSString *)phoneNumberRef;
CFRelease(phoneNumberRef);
NSLog(@" - %@ (%@)", phoneNumber, phoneLabel);
[phoneNumber release];
}
}
So I have a method to get all the contact phone numbers from the address book on the iPhone, but is there a way to get the phone number label? For example you can do this:
And I'd be looking to modify my method to print out the label (such as iPhone/Home/mobile/etc).
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef all = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex n = ABAddressBookGetPersonCount(addressBook);
for( int i = 0 ; i < n ; i++ )
{
ABRecordRef ref = CFArrayGetValueAtIndex(all, i);
NSString *firstName = (NSString *)ABRecordCopyValue(ref, kABPersonFirstNameProperty);
NSLog(@"Name %@", firstName);
ABMultiValueRef *phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
{
NSString *phoneLabel = @""; // ???
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);
//CFRelease(phones);
NSString *phoneNumber = (NSString *)phoneNumberRef;
CFRelease(phoneNumberRef);
NSLog(@" - %@ (%@)", phoneNumber, phoneLabel);
[phoneNumber release];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需使用 -
编辑
请参阅此答案有关
CFBridgingRelease
和__bridge_transfer
的注释。Simply use -
EDIT
Please see the notes for this answer about
CFBridgingRelease
and__bridge_transfer
.如果您要将记录添加到 AddressBook,这些预定义常量可能就是您想要的,
kABPersonPhoneMobileLabel
、kABPersonPhoneIPhoneLabel
,它们在文件 ABPerson.h 中定义。If you are adding records to the AddressBook, these predefined constants may be what you want,
kABPersonPhoneMobileLabel
,kABPersonPhoneIPhoneLabel
, which are defined in the file ABPerson.h.以下内容应该有所帮助:
the following should help: