How to get a list of contacts in address book only that have a fax number?

I'd like to get a list of all contacts that have a fax number and only those contacts. Any contacts with just an email or just a phone number I do not want to show.


If you haven't already you'll want to browse the ABAddressBook Reference

Iterate through all the records of the address book, and get the kABPersonPhoneProperty. This is a multivalue property, so iterate through all its labels. If the work fax (kABPersonPhoneWorkFAXLabel) or home fax (kABPersonPhoneHomeFAXLabel) labels are present, get those values.

Here's some quick-n-dirty sample 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 );

Need Your Help

How to export findbugs results from Eclipse findbugs plugin?

java eclipse-plugin findbugs

I have findbugs plugin for eclipse which when run on my project will show results in Bugs explorer clubbed by the type of bug.

NFC tag(for NfcA) scan works only from the second time

android nfc cordova-plugins onnewintent

I wrote a custom plugin to read blocks of data from an NfcA(i.e.non-ndef) tag. It seems to work fine , but only after the second scan. I am using Activity intent to derive the "NfcAdapter.EXTRA_TAG...