iPhone Tutorial for Beginner | Programmer | Developer

Help to build mobile applications for Apple Store

get Image from Contact stored in AddressBook [iPhone]

Posted by Adeem Basraa On April - 2 - 2009
New in iPhone Development? You can now follow this blog on google readers or subscribe for email or Twitter!
If my tutorial help you then please donate, so that i continue writing free tutorials for every developer/programmer/freelancer

Using this code you can retrieve the pictures of contact stored in your AddressBook!

ABAddressBookRef addressBook = ABAddressBookCreate();



NSMutableArray *people = [[[(NSArray*) ABAddressBookCopyArrayOfAllPeople(addressBook) autorelease] mutableCopy] autorelease];

[people sortUsingFunction:(int (*)(id, id, void *) ) ABPersonComparePeopleByName context:(void*)ABPersonGetSortOrdering()];

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

    if(ABPersonHasImageData(person)){
        image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(person)];
    }else{
        image = [UIImage imageNamed:@"contact_image.gif"];
    }
}

Popularity: 6% [?]

Related posts:

  1. iPhone Tutorial for Retrieving Contact information from AddressBook Introduction In this tutorial I will explain how you can...
  2. iPhone Tutorial for Creating a Splash Screen Introduction: Some people asked me about creating a splash screen...
  3. iPhone SDK Tutorial – {Part 4} Tips for UITableView Design [Add Header, Footer, Background Images & change Design] UITableView Tutorial: {Part 4} This tutorial will explain, how you...
  4. iPhone Programming Tutorial {Part 7}: Adding Pictures into your table using Interface builder Creating iPhone Application: Introduction: I am going to write series...
  5. Tutorial/Tips (Sorting & Filtering): Filter NSMutableArray and Sorting NSMutableArray by Ascending or Objects or Specified key or Key Value or by NSNumber Sorting objects held in an NSMutableArray is a pretty common...

5 Responses to “get Image from Contact stored in AddressBook [iPhone]”

  1. [...] April 4, 2009 at 2:25 PM (iPhone) (AddressBook, Contact, iPhone) Moved to Adeem.me [...]

  2. Asif says:

    How can we display address book images in our application

  3. admin says:

    yep you can do that. the code i already written get all the images from contact list , you just need to stored those images in some mutable array and used it anywhere you likes :)

  4. Amit says:

    I have more than 2k contacts to read form addressbook, but the reading code crashes ( low memory) after reading 2k records. Application have no leak in contacts reading code, i checked with leak application.

  5. Amit,

    the leak is in the line:
    image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(person)];

    which instead should read something like:

    CFDataRef imageData = ABPersonCopyImageData(person)];
    image = [UIImage imageWithData:(NSData *)imageData];
    CFRelease(imageData);

Leave a Reply

Support Me $5

Subscription Options: