Get photos from address book in iphone application

I want to get the contact name, photos from the Addressbook in my iphone application. I can get the contacts and store in array.but now I know how to also get the photos.the contacts the code that I use is as follows.

ABAddressBookRef ab=ABAddressBookCreate();
NSArray *arrTemp=(NSArray *)ABAddressBookCopyArrayOfAllPeople(ab);  

arrContact=[[NSMutableArray alloc] init];
for (int i=0;i<[arrTemp count];i++) 
{
    NSMutableDictionary *dicContact=[[NSMutableDictionary alloc] init];
    NSString *str=(NSString *) ABRecordCopyValue([arrTemp objectAtIndex:i], kABPersonFirstNameProperty);
    @try 
    {
        [dicContact setObject:str forKey:@"name"];
    }
    @catch (NSException * e) {
        [dicContact release];
        continue;
    }
    [arrContact addObject:dicContact];
    NSLog(@"mohit inside the loop");
    [dicContact release];
}

I want to get the photo and the name of the contacts in this array (arrContacts), and then display them in a table. Please give me a guide. thank

+5
source share
2 answers

In ARC mode

 NSData * imgData = (__bridge_transfer NSData *) ABPersonCopyImageDataWithFormat (record, kABPersonImageFormatThumbnail);

where record is a class object

ABRecordRef

Hope this helps

+6
source

In iOS 4+, you can get an image using:

ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatOriginalSize);

or

ABPersonCopyImageData(person);
+4

All Articles