-1

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

NoNaMe
  • 6,020
  • 30
  • 82
  • 110
DIVAKAR SRINIVASAN
  • 146
  • 1
  • 4
  • 17
  • possible duplicate of [iOS: Address Book](http://stackoverflow.com/questions/9013487/ios-address-book) – Marco Feb 11 '14 at 06:32

1 Answers1

0

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);



}
Sham
  • 475
  • 2
  • 7
  • User have to pick multiple contacts from his address book and i have to store that images in mutable array – DIVAKAR SRINIVASAN Oct 04 '12 at 12:10
  • OKay. So i think for this you have to put this data into a table view and use table view as multiple choice. And add all the values of the person into an array with key-value pair. May be this will help you. – Sham Oct 04 '12 at 12:14
  • Shameem@ I have read the contacts and i stored the contacts data in an dictionary i cant able to load those data in an table view.. Pls see this link..i took data in this format only . http://stackoverflow.com/questions/12757158/uitableview-data – DIVAKAR SRINIVASAN Oct 11 '12 at 04:56