获取联系人图片ios [英] Get a Contact Picture ios

查看:105
本文介绍了获取联系人图片ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何在下面的代码中添加姓氏名字,以便从我的手机中获取他们的联系人图片:

I am trying to figure out how to add persons last name and first name in this code below in order to get their contact image from my phone:

if(ABPersonHasImageData(aABRecordRef))
{
   UIImage *image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(aABRecordRef)];
   cell.imageView.image = image;
} else {
   UIImage *image1=[UIImage imageNamed:@"User.jpg"];
   cell.imageView.image=image1;
}

我也可能在这里丢失代码所以请填写它的区域需要。我只是想弄清楚如何将第一个,最后一个名称添加到上面的代码中,所以我知道当我到达该联系人时为其提取图像。

I could also be missing code here so please do fill in the areas where it is needed. I just cant figure out how to add the first,last name to the code above so i know when i have reached that contact to extract the image for it.

任何帮助都会很棒!谢谢!

Any help would be great! Thanks!

推荐答案

要获取FirstName和LastName,您可以使用:

To get the FirstName and LastName , you can use :

NSString *firstName = (NSString *)ABRecordCopyValue(aABRecordRef, kABPersonFirstNameProperty);
NSString *lastName = (NSString *)ABRecordCopyValue(aABRecordRef, kABPersonLastNameProperty);

这里显示如何按号码搜索并使用ABAddressBook获取图像

但是你想搜索By FirstName和LastName。所以根据文档,您应该使用 - recordsMatchingSearchElement:多个参数的方法。

But you want to search By FirstName and LastName. So According to the Documentation , you should use -recordsMatchingSearchElement: method for Multiple Arguments.

获得匹配的数据后,您可以使用以下代码提取图像:

Once you get the matched Data , you can extract the image using below code :

CFDataRef imageData = ABPersonCopyImageData(aABRecordRef);
UIImage *image = [UIImage imageWithData:(NSData *)imageData];
CFRelease(imageData);

希望你从中获得有用的东西。

Hope you get something useful from this.

这篇关于获取联系人图片ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆