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 ...
随机推荐
- 003_vim使用tip
vim 使用tip 编写python程序 自动插入头信息: #!/usr/bin/env python # coding=utf-8 输入.或按TAB键会触发代码补全功能 :w保存代码之后会自动检查代 ...
- jquery-扩展
jQuery扩展三种方式:$.extend,$.fn.extend,外部文件. 1)jQuery.extend(object) 调用 $.方法 2)jQuery.fn.extend(object) ...
- javascript之继承
主要是参考了<JavaScript高级程序设计(第三版)>这本书,根据自己的理解,做了下面的记录 继承是面向对象(OO)语言里面的概念,有俩种继承方式:接口继承和实现继承.接口继承只继承方 ...
- 【转】卖萌的大牛你桑不起啊 ——记CVPR2011一篇极品文章
来源:http://blog.renren.com/share/228707015/7197269922 作者 : 庞宇 CVPR2011正在如火如荼的进行中,在网上能看到的部分文章中,我终于找到一篇 ...
- Luogu P3957 跳房子
题面 跳房子,也叫跳飞机,是一种世界性儿童游戏,也是中国民间传统的体育游戏之一. 跳房子的游戏规则如下: 在地面上确定一个起点,然后在起点右侧画 n 个格子,这些格子都在同一条直线上.每个格子内有一 ...
- 图学ES6-4.字符串的扩展
- 西安电子科技大学第16届程序设计竞赛网络同步赛 G-小国的复仇
sb找规律. 分解因数. #include<bits/stdc++.h> #define LL long long #define fi first #define se second # ...
- 使用python爬取整本《盗墓笔记》
一.前言 <盗墓笔记>是一本经典的盗墓题材小说,故事情节引人入胜.本文将使用python2.7通过小说网站http://www.daomubiji.com/来爬取整本盗墓笔记并保存,在这一 ...
- linux 安装redis4.0
1.安装redis 第一步:下载redis安装包 wget http://download.redis.io/releases/redis-4.0.6.tar.gz 1 2 3 4 5 6 7 8 9 ...
- java数据结构之树
树定义和基本术语定义树(Tree)是n(n≥0)个结点的有限集T,并且当n>0时满足下列条件: (1)有且仅有一个特定的称为根(Root)的结点: (2)当n>1时,其余结 ...