问题描述
我有两个tableViewControllers。第一个有联系人列表。另一个显示详细的人的信息。
I have two tableViewControllers. The first one has a list of contacts. The another one shows detailed person's information.
第一个tableViewController的代码块
A chunk of code of first tableViewController
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
NSArray *allPeople = (__bridge_transfer NSArray*)ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source,kABPersonSortByFirstName);
for ( int i = 0; i < [allPeople count]; i++ )
{
...
contactClass = [[ContactClass alloc] initWithName:name surName:surName manID:[allPeople objectAtIndex:i]];
...
}
第二个tableViewController的代码块
A chunck of code of second tableViewController
ABRecordRef person = (__bridge ABRecordRef)contactClass.manID;
BOOL isHasImage = ABPersonHasImageData(person);
变量isHasImage始终为false,即使联系人具有头像。我甚至在第一个tableViewController上检查了这个,如果有人有头像,那么它返回true和图像。
Variable isHasImage is always false, even if contact has an avatar. I even checked this on the first tableViewController and if person has an avatar, then it returns true and image.
有谁知道为什么我无法获取联系人图像?
Does anyone knows why I can't get contacts image?
p.s。 contactClass.manID
的类型为 id
。它有一个正确的地址,因为 ABMultiValueRef multiValue = ABRecordCopyValue((__ bridge ABRecordRef)contactClass.manID,kABPersonPhoneProperty);
在第二个tableViewController中返回正确的值
p.s. contactClass.manID
is type of id
. It has a correct adress, because ABMultiValueRef multiValue = ABRecordCopyValue((__bridge ABRecordRef)contactClass.manID, kABPersonPhoneProperty);
returns correct value in the second tableViewController
推荐答案
我可能为你找到一个解决方案为时已晚,但也许这会帮助那些遇到同样问题的人。
看起来像 ABPersonHasImageData()
和 ABPersonCopyImageDataWithFormat()
在<$ c $上无法正常工作c> ABRecordRef 从使用 ABAddressBookCopyArrayOfAllPeople()
获得的数组中复制(例如 ABContactRef
) ,在iOS 5.x上的leas。您可以这样解决:
I may be too late for a solution for you, but maybe this will help others that are stuck with the same problem. Looks like ABPersonHasImageData()
and ABPersonCopyImageDataWithFormat()
don't work as expected on ABRecordRef
copies (e.g. an ABContactRef
from an array obtained using ABAddressBookCopyArrayOfAllPeople()
), at leas on iOS 5.x. You may workaround it like this:
- (UIImage*)imageForContact: (ABRecordRef)contactRef {
UIImage *img = nil;
// can't get image from a ABRecordRef copy
ABRecordID contactID = ABRecordGetRecordID(contactRef);
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef origContactRef = ABAddressBookGetPersonWithRecordID(addressBook, contactID);
if (ABPersonHasImageData(origContactRef)) {
NSData *imgData = (NSData*)ABPersonCopyImageDataWithFormat(origContactRef, kABPersonImageFormatOriginalSize);
img = [UIImage imageWithData: imgData];
[imgData release];
}
CFRelease(addressBook);
return img;
}
这篇关于iOS无法获得人的形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!