Search code examples
iosaddressbook

Get image contact in address book on iOS


I'm new using the Address book and I would try to get some info for the contacts in the phone. Is possible get the image contact of all the contacts? This will be for iOS4 or higher.

Thanks in advance!


Solution

  • Yes it is completely possible, you simply ask each person record whether it has an image:

    See the documentation: http://developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html#//apple_ref/doc/uid/TP40007210

    Relevant Functions:

    ABPersonHasImageData(person)
    ABPersonCopyImageDataWithFormat(person)
    

    The ABPersonCopyImageDataWithFormat returns a CFDataRef. Convert it to NSData with this (ARC) NSData* data = (__bridge_transfer NSData*) cfData;

    An image can then be created with [UIImage imageWithData:data]