views:

20

answers:

1

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

A: 

Hi simply follow the link it has solution, click here

I hope it will help you

Sivanathan
Hi, thanks for your answer, but this does not help me. I can add an image without problems if one does not (and never has) exist for a contact. The problem is if there is an existing image or an image used to exist (i.e. was deleted through editing the contact in the address book app).
Mark McFarlane