[英]Set image for contact iOS
我正在使用ABPeoplePickerNavigationController
作為聯系人的表示表。 通過點擊聯系人,我需要為其設置新圖像。 我添加了代碼以委派更改人的數據,但不能更改圖像。 有什么建議么?
這是我的代碼如下:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
NSData *dataRef = UIImagePNGRepresentation(self.theImage);
CFDataRef cfdata = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);
CFErrorRef error;
ABPersonRemoveImageData(person, &error); // clean any image first from ref
if (ABAddressBookSave(_addressBook, &error))
{
ABPersonSetImageData(person, cfdata, &error);
ABAddressBookSave(_addressBook, &error);
}
CFRelease(cfdata);
[self dismissViewControllerAnimated:YES completion:nil];
return NO;
}
我從這里下載了示例: 鏈接
要檢查其工作原理,您可以下載代碼並在下面用我的代碼修改委托。
您需要通過ABAddressBookSave()
保存更改
另外,請記住,如果您的聯系人還沒有圖像,則在使用ABPersonSetImageData
時將同時添加縮略圖和全尺寸圖像。 但是,如果您的聯系人已經具有完整尺寸的圖像,則在使用ABPersonSetImageData
時僅會設置縮略圖。
// this is not production level code. method call return values and errors
// need to be handled properly
ABPersonRemoveImageData(person, &error); // clean any image first from ref
if (ABAddressBookSave(addressBook, &error))
{
ABPersonSetImageData(person, cfdata, &error);
ABAddressBookSave(addressBook, &error)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.