Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

asifpv

macrumors newbie
Original poster
Apr 13, 2009
11
0
Hi all,


How to add an UIImage to address book contact from another application.

Thanx,
asif
 
Please take the time to read the documentation before posting questions. It's pretty obvious (it took me all of 20 seconds to find this) that this method is what you need to execute. The rest of the documentation will tell you how to get a reference to the correct ABPersonRef object.
 
Hi robbieduncan,

Thanx for your reply, i did in my app like the following , but its not working..

CFDataRef imageData = CGDataProviderCopyData(CGImageGetDataProvider(empImage.CGImage));

ABPersonSetImageData(person, imageData, nil);

ABAddressBookAddRecord(addrBook, person, nil);

ABAddressBookSave(addrBook, nil);


Please help me...


Thanks,
Asif
 
use UIImagePNGRepresentation

UIImage *personImage;
personImage = [UIImage imageNamed:mad:"bl.png"];
NSData *dataRef = UIImagePNGRepresentation(personImage);
CFDataRef dr = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);

ABPersonSetImageData(newPerson, dr, &error);
if (error != NULL) {
NSLog(@"AB Person Set Image Failed");
}

ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);
ABAddressBookSave(iPhoneAddressBook, &error);
if (error != NULL) {
NSLog(@"Address Book Save Failed");
}
CFRelease(dr);
CFRelease(newPerson);
CFRelease(iPhoneAddressBook);
 
NSData is also toll-free bridged with CFData, so you should be able to type-cast your NSData object as a CFData one and pass it in to "ABPersonSetImageData". This can save you a step or two.

Code:
NSData *data = UIImagePNGRepresentation(newImage);

ABPersonSetImageData(newPerson, (CFData *)data, &error);
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.