If you do not want to browse the ABAddressBook Reference
Iterate over all address book entries and get kABPersonPhoneProperty. This is a multi-valued property, so repeat all of its labels. If work fax ( kABPersonPhoneWorkFAXLabel) or home fax ( kABPersonPhoneHomeFAXLabel) marks are present , obtain these values.
Here is sample code with fast n-dirty code:
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
for( CFIndex personIndex = 0; personIndex < nPeople; personIndex++ ) {
ABRecordRef person = CFArrayGetValueAtIndex( allPeople, personIndex );
CFStringRef name = ABRecordCopyCompositeName( person );
ABMultiValueRef phones = ABRecordCopyValue( person, kABPersonPhoneProperty );
NSString* homeFax = nil;
NSString* workFax = nil;
BOOL hasFax = NO;
for( CFIndex phoneIndex = 0; phoneIndex < ABMultiValueGetCount( phones ); phoneIndex++ ) {
NSString* aLabel = (NSString*) ABMultiValueCopyLabelAtIndex( phones, phoneIndex );
if( [aLabel isEqualToString:(NSString*)kABPersonPhoneHomeFAXLabel] ) {
homeFax = (NSString*) ABMultiValueCopyValueAtIndex( phones, phoneIndex );
hasFax = YES;
}
else if( [aLabel isEqualToString:(NSString*)kABPersonPhoneWorkFAXLabel]) {
workFax = (NSString*) ABMultiValueCopyValueAtIndex( phones, phoneIndex );
hasFax = YES;
}
[aLabel release];
}
if( hasFax ) {
NSLog( @"%@: %@, %@", name,
homeFax == nil ? @"" : homeFax,
workFax == nil ? @"" : workFax );
if( homeFax ) [homeFax release];
if( workFax ) [workFax release];
}
CFRelease( phones );
CFRelease( name );
}
CFRelease( allPeople );
CFRelease( addressBook );
source
share