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
ABAddres开发者_开发问答sBookRef 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);
See:
Setting Address Book image for a contact doesn't seem to work
and
ABPersonSetImageData Only Altering the Contact Thumbnail and Not the Full Pic
精彩评论