How to save image to iphone's AddressBook using SDK API ?
Posted
by apple.dev
on Stack Overflow
See other posts from Stack Overflow
or by apple.dev
Published on 2010-04-19T08:07:30Z
Indexed on
2010/04/19
8:13 UTC
Read the original article
Hit count: 744
iphone
|addressbook
My purpose is to process one image from image library, and save this image directly to one person record (i,e, "Tom" ), which is selected from AddressBook, I can see the new image replace Tom's previous image, but I can not save it to AddressBook.
I implemented delegate ABPeoplePickerNavigationControllerDelegate, and using following logics, but whatever I tried, modified records can not be saved to address books.
Any clues or suggest ? Thanks
ABAddressBookRef addressBook= ABAddressBookCreate();
CFErrorRef error = NULL;
BOOL wantToSaveChanges = YES;
ABRecordSetValue(person, kABPersonFirstNameProperty, @"Shi", &error);//, &error)
NSData * dataRef = UIImagePNGRepresentation(cellImage);
ABPersonSetImageData(person, dataRef, &error);
if (ABAddressBookHasUnsavedChanges(addressBook)) {\
NSLog(@"need to save ");
if (wantToSaveChanges) {
ABAddressBookSave(addressBook, &error);
} else {
ABAddressBookRevert(addressBook);
}
}else {
NSLog(@"no changes");
}
if (error != NULL) {/*... Handle error. ...*/
NSLog(@"error happened here " );
}
CFRelease(addressBook);
© Stack Overflow or respective owner