ios 获得通讯录中联系人的所有属性 亲测,可行 兼容io6 和 ios 7
//获取通讯录中的所有属性,并存储在 textView 中,已检验,切实可行。兼容io6 和 ios 7 ,而且ios7还没有权限确认提示。
-(void)getAddressBook
{
ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef results = ABAddressBookCopyArrayOfAllPeople(addressBook); for(int i = ; i < CFArrayGetCount(results); i++)
{
ABRecordRef person = CFArrayGetValueAtIndex(results, i);
//读取firstname
NSString *personName = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
if(personName != nil)
textView.text = [textView.text stringByAppendingFormat:@"\n姓名:%@\n",personName];
//读取lastname
NSString *lastname = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
if(lastname != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",lastname];
//读取middlename
NSString *middlename = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty);
if(middlename != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",middlename];
//读取prefix前缀
NSString *prefix = (NSString*)ABRecordCopyValue(person, kABPersonPrefixProperty);
if(prefix != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",prefix];
//读取suffix后缀
NSString *suffix = (NSString*)ABRecordCopyValue(person, kABPersonSuffixProperty);
if(suffix != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",suffix];
//读取nickname呢称
NSString *nickname = (NSString*)ABRecordCopyValue(person, kABPersonNicknameProperty);
if(nickname != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",nickname];
//读取firstname拼音音标
NSString *firstnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonFirstNamePhoneticProperty);
if(firstnamePhonetic != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",firstnamePhonetic];
//读取lastname拼音音标
NSString *lastnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonLastNamePhoneticProperty);
if(lastnamePhonetic != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",lastnamePhonetic];
//读取middlename拼音音标
NSString *middlenamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNamePhoneticProperty);
if(middlenamePhonetic != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",middlenamePhonetic];
//读取organization公司
NSString *organization = (NSString*)ABRecordCopyValue(person, kABPersonOrganizationProperty);
if(organization != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",organization];
//读取jobtitle工作
NSString *jobtitle = (NSString*)ABRecordCopyValue(person, kABPersonJobTitleProperty);
if(jobtitle != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",jobtitle];
//读取department部门
NSString *department = (NSString*)ABRecordCopyValue(person, kABPersonDepartmentProperty);
if(department != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",department];
//读取birthday生日
NSDate *birthday = (NSDate*)ABRecordCopyValue(person, kABPersonBirthdayProperty);
if(birthday != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",birthday];
//读取note备忘录
NSString *note = (NSString*)ABRecordCopyValue(person, kABPersonNoteProperty);
if(note != nil)
textView.text = [textView.text stringByAppendingFormat:@"%@\n",note];
//第一次添加该条记录的时间
NSString *firstknow = (NSString*)ABRecordCopyValue(person, kABPersonCreationDateProperty);
NSLog(@"第一次添加该条记录的时间%@\n",firstknow);
//最后一次修改該条记录的时间
NSString *lastknow = (NSString*)ABRecordCopyValue(person, kABPersonModificationDateProperty);
NSLog(@"最后一次修改該条记录的时间%@\n",lastknow); //获取email多值
ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty);
int emailcount = ABMultiValueGetCount(email);
for (int x = ; x < emailcount; x++)
{
//获取email Label
NSString* emailLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(email, x));
//获取email值
NSString* emailContent = (NSString*)ABMultiValueCopyValueAtIndex(email, x);
textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",emailLabel,emailContent];
}
//读取地址多值
ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty);
int count = ABMultiValueGetCount(address); for(int j = ; j < count; j++)
{
//获取地址Label
NSString* addressLabel = (NSString*)ABMultiValueCopyLabelAtIndex(address, j);
textView.text = [textView.text stringByAppendingFormat:@"%@\n",addressLabel];
//获取該label下的地址6属性
NSDictionary* personaddress =(NSDictionary*) ABMultiValueCopyValueAtIndex(address, j);
NSString* country = [personaddress valueForKey:(NSString *)kABPersonAddressCountryKey];
if(country != nil)
textView.text = [textView.text stringByAppendingFormat:@"国家:%@\n",country];
NSString* city = [personaddress valueForKey:(NSString *)kABPersonAddressCityKey];
if(city != nil)
textView.text = [textView.text stringByAppendingFormat:@"城市:%@\n",city];
NSString* state = [personaddress valueForKey:(NSString *)kABPersonAddressStateKey];
if(state != nil)
textView.text = [textView.text stringByAppendingFormat:@"省:%@\n",state];
NSString* street = [personaddress valueForKey:(NSString *)kABPersonAddressStreetKey];
if(street != nil)
textView.text = [textView.text stringByAppendingFormat:@"街道:%@\n",street];
NSString* zip = [personaddress valueForKey:(NSString *)kABPersonAddressZIPKey];
if(zip != nil)
textView.text = [textView.text stringByAppendingFormat:@"邮编:%@\n",zip];
NSString* coutntrycode = [personaddress valueForKey:(NSString *)kABPersonAddressCountryCodeKey];
if(coutntrycode != nil)
textView.text = [textView.text stringByAppendingFormat:@"国家编号:%@\n",coutntrycode];
} //获取dates多值
ABMultiValueRef dates = ABRecordCopyValue(person, kABPersonDateProperty);
int datescount = ABMultiValueGetCount(dates);
for (int y = ; y < datescount; y++)
{
//获取dates Label
NSString* datesLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates, y));
//获取dates值
NSString* datesContent = (NSString*)ABMultiValueCopyValueAtIndex(dates, y);
textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",datesLabel,datesContent];
}
//获取kind值
CFNumberRef recordType = ABRecordCopyValue(person, kABPersonKindProperty);
if (recordType == kABPersonKindOrganization) {
// it's a company
NSLog(@"it's a company\n");
} else {
// it's a person, resource, or room
NSLog(@"it's a person, resource, or room\n");
} //获取IM多值
ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty);
for (int l = ; l < ABMultiValueGetCount(instantMessage); l++)
{
//获取IM Label
NSString* instantMessageLabel = (NSString*)ABMultiValueCopyLabelAtIndex(instantMessage, l);
textView.text = [textView.text stringByAppendingFormat:@"%@\n",instantMessageLabel];
//获取該label下的2属性
NSDictionary* instantMessageContent =(NSDictionary*) ABMultiValueCopyValueAtIndex(instantMessage, l);
NSString* username = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageUsernameKey];
if(username != nil)
textView.text = [textView.text stringByAppendingFormat:@"username:%@\n",username]; NSString* service = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageServiceKey];
if(service != nil)
textView.text = [textView.text stringByAppendingFormat:@"service:%@\n",service];
} //读取电话多值
ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);
for (int k = ; k<ABMultiValueGetCount(phone); k++)
{
//获取电话Label
NSString * personPhoneLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phone, k));
//获取該Label下的电话值
NSString * personPhone = (NSString*)ABMultiValueCopyValueAtIndex(phone, k); textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",personPhoneLabel,personPhone];
} //获取URL多值
ABMultiValueRef url = ABRecordCopyValue(person, kABPersonURLProperty);
for (int m = ; m < ABMultiValueGetCount(url); m++)
{
//获取电话Label
NSString * urlLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(url, m));
//获取該Label下的电话值
NSString * urlContent = (NSString*)ABMultiValueCopyValueAtIndex(url,m); textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",urlLabel,urlContent];
} //读取照片
NSData *image = (NSData*)ABPersonCopyImageData(person); UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
[myImage setImage:[UIImage imageWithData:image]];
myImage.opaque = YES;
[textView addSubview:myImage];
} CFRelease(results);
CFRelease(addressBook);
}
ios 获得通讯录中联系人的所有属性 亲测,可行 兼容io6 和 ios 7的更多相关文章
- iOS 获得通讯录中联系人的所有属性--b
ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef results = ABAddressBookCopyArrayOfA ...
- IOS 获得通讯录中联系人的所有属性 备用参考
ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef results = ABAddressBookCopyArrayOfA ...
- iOS 获取通讯录中联系人的所有属性 by - zfqj
1 ABAddressBookRef addressBook = ABAddressBookCreate(); 2 3 CFArrayRef results = ABAddressBookCopyAr ...
- ios(包括6、7)应用程序引用系统通讯录的方法 [亲测可行]
由于ios系统对用户隐私的控制,第三方应用程序只能通过苹果官方接口调用系统通讯录,不能像android那样直接操作通讯录数据库. 一般地,使用系统自带通讯录的方法有两种,一种是直接将整个通讯录 ...
- 亲测可行,AndroidStudio 究竟如何配置gradle
一.你不想看到的 Gradle Build Running 话说在天朝当程序员也是很不容易的,不管是查阅资料还是下载东西,很多时候你会发现自己上网姿势不对,当然对大多数程序员来说,这都不是事儿.这次重 ...
- MyEclipse 2017 ci6 安装反编译插件(本人自己摸索的方法,亲测可行)
注: 本文来源于:Smile_Miracle 的< MyEclipse 2017 ci6 安装反编译插件(本人自己摸索的方法,亲测可行) > 第一步:关闭ME,去一下地址下载jad的反编译 ...
- IOS 获取通讯录中信息
获取通讯录中信息 一. 我们设置一个ABAddressBookRef类型的属性addressBook. 二. 要获得通讯录中的信息,我们需要获取访问通讯录的权限. 在运行下面的获取权限的方法的时候,系 ...
- pycharm 配置autopep8(亲测可行)
autopep8是一个可以将Python代码自动排版为PEP8风格第三方包,使用它可以轻松地排版出格式优美整齐的代码.网络上有很多介绍如何在pycharm中配置autopep8的方案,但很多方案中还是 ...
- vegas pro 15解决导入的视频和音频有噪声问题,亲测可行
中文步骤: 按住Shift->点击选项->首选项,松开Shift 点击右上角"内部"选项卡,在最下面的搜索栏输入SO4 找到第二项Enable So4 Compound ...
随机推荐
- 2012 Dhaka
2012 Dhaka B - Wedding of Sultan 题目描述:给出一棵树的\(dfs\)序(只要经过就会记录),求每个点的度 solution 按\(dfs\)序的规则还原这棵树就好了. ...
- Ext.util.Format.date 时间格式的设置与转换
Ext.util.Format.date 如下这段简单的代码: var d = new Date(value.time); var s = Ext.util.Format.date(d, 'Y-m- ...
- Laravel 的 JSON API 接口自动化测试
Laravel 自带了两种测试类型 Feature Test: 功能测试.针对类似接口这种流程性的测试. Unit Test: 单元测试.针对单个函数这种输入输出结果的测试. 新建一个 Feature ...
- 探究 encode 和 decode 的使用问题(Python)
很多时候在写Python程序的时候都要在头部添加这样一行代码 #coding: utf-8 或者是这样 # -*- coding:utf-8 -*- 等等 这行代码的意思就是设定同一编码格式为utf- ...
- 002.SMB安装与端口
一 安装所需包 samba:主服务包 samba-client:客户端 samba-common:通用工具和宏文件,存在于客户端和服务端 samba-libs:库 samba-winbind:wind ...
- 关于configure: error: no acceptable C compiler found in $PATH
Linux系统在安装python3的时候报错: $ ./configure --prefix=/usr/local/python3 checking build system type... x86_ ...
- Python - 计算个人所得税
最近在学python,写了个计算个人所得税计算的脚本,分享. 以下为python3适用版本 #!/usr/bin/python # -*- coding: UTF-8 -*- # 该python脚本用 ...
- Spring框架学习——Spring的体系结构详解
1.Spring简介 Spring是一个轻量级Java开发框架,最早有Rod Johnson创建,目的是为了解决企业级应用开发的业务逻辑层和其他各层的耦合问题.它是一个分层的JavaSE/JavaEE ...
- CSS3选择器02—CSS3部分选择器
该部分主要为CSS3新增的选择器 接上一篇 CSS(CSS3)选择器(1) 一.通用兄弟选择器: 24:E ~ F,匹配任何E元素之后的同级F元素. div ~ p{ background-color ...
- OSI 7层 TCP/IP 4层
在网络层有{ IP协议:IP协议是用于将多个包交换网络连接起来的,它在源地址和目的地址之间传送一种称之为数据包的东西,它还提供对数据大小的重新组装功能,以适应不同网络对包大小的要求. ICMP协议:I ...