0

In my app I receive a json response from the server which contains phone numbers. I wan't to show the full name of the contact if the number is stored in the addressbook. Similar to the phone app when you type in a number manually the iPhone shows the name if the number is stored in the addressbook.

I can't find any tutorial on the web. Probably due to the search string which always contains iphone, number and contact and I get a lot of results but nothing helpful.

Can anybody give me a hint where to look or how to do that?

Kara
  • 6,115
  • 16
  • 50
  • 57
rockstarberlin
  • 1,853
  • 1
  • 18
  • 31
  • https://developer.apple.com/library/iOs/documentation/AddressBook/Reference/ABAddressBookRef_iPhoneOS/Reference/reference.html – Gabriele Petronella Nov 17 '13 at 17:23
  • 1
    https://developer.apple.com/library/iOs/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Introduction.html#//apple_ref/doc/uid/TP40007744 – Gabriele Petronella Nov 17 '13 at 17:24

1 Answers1

0

Got the solution form here

How to search the iphone address book for a specific phone number?

- (void) scanAddressBookSample
{
NSUInteger i;
NSUInteger k;

ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *people = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);

if ( people==nil )
    {
    NSLog(@"NO ADDRESS BOOK ENTRIES TO SCAN");
    CFRelease(addressBook);
    return;
    }

for ( i=0; i<[people count]; i++ )
    {
    ABRecordRef person = (ABRecordRef)[people objectAtIndex:i];

    //
    // Phone Numbers
    //
    ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
    CFIndex phoneNumberCount = ABMultiValueGetCount( phoneNumbers );

    for ( k=0; k<phoneNumberCount; k++ )
        {
        CFStringRef phoneNumberLabel = ABMultiValueCopyLabelAtIndex( phoneNumbers, k );
        CFStringRef phoneNumberValue = ABMultiValueCopyValueAtIndex( phoneNumbers, k );
        CFStringRef phoneNumberLocalizedLabel = ABAddressBookCopyLocalizedLabel( phoneNumberLabel );    // converts "_$!<Work>!$_" to "work" and "_$!<Mobile>!$_" to "mobile"

        // Find the ones you want here
        //
        NSLog(@"-----PHONE ENTRY -> %@ : %@", phoneNumberLocalizedLabel, phoneNumberValue );

        CFRelease(phoneNumberLocalizedLabel);
        CFRelease(phoneNumberLabel);
        CFRelease(phoneNumberValue);
        }
    }

[people release];
CFRelease(addressBook);
}
Community
  • 1
  • 1
rockstarberlin
  • 1,853
  • 1
  • 18
  • 31