IOS: AddressBook Ui Framework

1.3k Views Asked by At

I want to select multiple contacts from an address book and i want to store the images of the selected persons in an mutable array. I have searched through the internet completely but i cant get any samples. Any one please help

Thanks in advance

1

There are 1 best solutions below

3
On

First You have to add the
"AddressBook.framework" framework and add header file :

import.

// this method 
  #pragma mark- find all contacts email id
   -(void)getFilterEmailid{



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];
    NSString *home=@"";
    NSString *work=@"";
    //
    // Phone Numbers
    //
    ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonEmailProperty);
    CFIndex phoneNumberCount = ABMultiValueGetCount( phoneNumbers );


    // Here we can get the Image ref 

    CFDataRef imageData = ABPersonCopyImageData(person);
    // This is the Image Data you can use as you want to.
    NSData *data = (NSData *)imageData;




    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 );
        home=[(NSString*)phoneNumberLocalizedLabel copy ];
        work=[(NSString *)phoneNumberValue copy];
        NSLog(@"home=%@  work=%@",home,work);
        CFRelease(phoneNumberLocalizedLabel);
        CFRelease(phoneNumberLabel);
        CFRelease(phoneNumberValue);

        // This is my array i save only the Email id. You can save what value you want
        [emailIdArray addObject:work];
    }


}

[people release];
CFRelease(addressBook);



}