View Full Version : Save image to address book
asifpv
Apr 21, 2009, 08:51 AM
Hi all,
How to add an UIImage to address book contact from another application.
Thanx,
asif
robbieduncan
Apr 21, 2009, 09:24 AM
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 (http://developer.apple.com/iphone/library/documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html#//apple_ref/c/func/ABPersonSetImageData) is what you need to execute. The rest of the documentation will tell you how to get a reference to the correct ABPersonRef object.
asifpv
Apr 22, 2009, 04:20 AM
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
robbieduncan
Apr 22, 2009, 04:24 AM
Instead of passing nil for the error arguments why not pass and check for errors like you are supposed to?
satyamtyagi
Nov 19, 2009, 12:47 AM
UIImage *personImage;
personImage = [UIImage imageNamed:@"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);
North Bronson
Nov 19, 2009, 01:31 PM
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.
NSData *data = UIImagePNGRepresentation(newImage);
ABPersonSetImageData(newPerson, (CFData *)data, &error);
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.