开发者

ABPersonSetImageData works if no image, does nothing if image exists

开发者 https://www.devze.com 2023-01-08 14:27 出处:网络
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 sh开发

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 sh开发者_运维百科ouldContinueAfterSelectingPerson:(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


Hi simply follow the link it has solution, click here

I hope it will help you

0

精彩评论

暂无评论...
验证码 换一张
取 消