Hi all, I'm stuck and don't know what to do. The apple docs don't seem to cover this very well.
My code:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
NSDictionary *info = [self selectedProjectInfo];
ABAddressBookRef addressBook = ABAddressBookCreate();
CFErrorRef error = nil;
if (ABPersonSetImageData(person, (CFDataRef)(UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[info objectForKey:@"ImagePath"]], 1.0f)), &error))
{
ABAddressBookAddRecord(addressBook, person, &error);
NSLog(@"Set contact photo %@", error);
if (ABAddressBookHasUnsavedChanges(addressBook))
{
NSLog(@"Changes made to address book");
}
else {
NSLog(@"No changes made to address book");
}
if (ABAddressBookSave(addressBook, &error))
{
NSLog(@"Saved");
UIAlertView *contactSuccessAlert = [[UIAlertView alloc] initWithTitle:@"Success" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[contactSuccessAlert show];
[contactSuccessAlert release];
}
else {
NSLog(@"Not saved");
}
}
else {
NSLog(@"Error saving contact photo %@", error);
}
CFRelease(addressBook);
[self.navigationController dismissModalViewControllerAnimated:YES];
return NO;
}
It works fine if there is no existing image in the contact, but if one already exists it's not replaced. Does anyone know what I should do?
Many thanks in advance