1 ABAddressBookRef addressBook = ABAddressBookCreate();
2
3 CFArrayRef results = ABAddressBookCopyArrayOfAllPeople(addressBook);
4
5 for(int i = 0; i < CFArrayGetCount(results); i++)
6 {
7 ABRecordRef person = CFArrayGetValueAtIndex(results, i);
8 //读取firstname
9 NSString *personName = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
10 if(personName != nil)
11 textView.text = [textView.text stringByAppendingFormat:@"\n姓名:%@\n",personName];
12 //读取lastname
13 NSString *lastname = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
14 if(lastname != nil)
15 textView.text = [textView.text stringByAppendingFormat:@"%@\n",lastname];
16 //读取middlename
17 NSString *middlename = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty);
18 if(middlename != nil)
19 textView.text = [textView.text stringByAppendingFormat:@"%@\n",middlename];
20 //读取prefix前缀
21 NSString *prefix = (NSString*)ABRecordCopyValue(person, kABPersonPrefixProperty);
22 if(prefix != nil)
23 textView.text = [textView.text stringByAppendingFormat:@"%@\n",prefix];
24 //读取suffix后缀
25 NSString *suffix = (NSString*)ABRecordCopyValue(person, kABPersonSuffixProperty);
26 if(suffix != nil)
27 textView.text = [textView.text stringByAppendingFormat:@"%@\n",suffix];
28 //读取nickname呢称
29 NSString *nickname = (NSString*)ABRecordCopyValue(person, kABPersonNicknameProperty);
30 if(nickname != nil)
31 textView.text = [textView.text stringByAppendingFormat:@"%@\n",nickname];
32 //读取firstname拼音音标
33 NSString *firstnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonFirstNamePhoneticProperty);
34 if(firstnamePhonetic != nil)
35 textView.text = [textView.text stringByAppendingFormat:@"%@\n",firstnamePhonetic];
36 //读取lastname拼音音标
37 NSString *lastnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonLastNamePhoneticProperty);
38 if(lastnamePhonetic != nil)
39 textView.text = [textView.text stringByAppendingFormat:@"%@\n",lastnamePhonetic];
40 //读取middlename拼音音标
41 NSString *middlenamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNamePhoneticProperty);
42 if(middlenamePhonetic != nil)
43 textView.text = [textView.text stringByAppendingFormat:@"%@\n",middlenamePhonetic];
44 //读取organization公司
45 NSString *organization = (NSString*)ABRecordCopyValue(person, kABPersonOrganizationProperty);
46 if(organization != nil)
47 textView.text = [textView.text stringByAppendingFormat:@"%@\n",organization];
48 //读取jobtitle工作
49 NSString *jobtitle = (NSString*)ABRecordCopyValue(person, kABPersonJobTitleProperty);
50 if(jobtitle != nil)
51 textView.text = [textView.text stringByAppendingFormat:@"%@\n",jobtitle];
52 //读取department部门
53 NSString *department = (NSString*)ABRecordCopyValue(person, kABPersonDepartmentProperty);
54 if(department != nil)
55 textView.text = [textView.text stringByAppendingFormat:@"%@\n",department];
56 //读取birthday生日
57 NSDate *birthday = (NSDate*)ABRecordCopyValue(person, kABPersonBirthdayProperty);
58 if(birthday != nil)
59 textView.text = [textView.text stringByAppendingFormat:@"%@\n",birthday];
60 //读取note备忘录
61 NSString *note = (NSString*)ABRecordCopyValue(person, kABPersonNoteProperty);
62 if(note != nil)
63 textView.text = [textView.text stringByAppendingFormat:@"%@\n",note];
64 //第一次添加该条记录的时间
65 NSString *firstknow = (NSString*)ABRecordCopyValue(person, kABPersonCreationDateProperty);
66 NSLog(@"第一次添加该条记录的时间%@\n",firstknow);
67 //最后一次修改該条记录的时间
68 NSString *lastknow = (NSString*)ABRecordCopyValue(person, kABPersonModificationDateProperty);
69 NSLog(@"最后一次修改該条记录的时间%@\n",lastknow);
70
71 //获取email多值
72 ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty);
73 int emailcount = ABMultiValueGetCount(email);
74 for (int x = 0; x < emailcount; x++)
75 {
76 //获取email Label
77 NSString* emailLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(email, x));
78 //获取email值
79 NSString* emailContent = (NSString*)ABMultiValueCopyValueAtIndex(email, x);
80 textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",emailLabel,emailContent];
81 }
82 //读取地址多值
83 ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty);
84 int count = ABMultiValueGetCount(address);
85
86 for(int j = 0; j < count; j++)
87 {
88 //获取地址Label
89 NSString* addressLabel = (NSString*)ABMultiValueCopyLabelAtIndex(address, j);
90 textView.text = [textView.text stringByAppendingFormat:@"%@\n",addressLabel];
91 //获取該label下的地址6属性
92 NSDictionary* personaddress =(NSDictionary*) ABMultiValueCopyValueAtIndex(address, j);
93 NSString* country = [personaddress valueForKey:(NSString *)kABPersonAddressCountryKey];
94 if(country != nil)
95 textView.text = [textView.text stringByAppendingFormat:@"国家:%@\n",country];
96 NSString* city = [personaddress valueForKey:(NSString *)kABPersonAddressCityKey];
97 if(city != nil)
98 textView.text = [textView.text stringByAppendingFormat:@"城市:%@\n",city];
99 NSString* state = [personaddress valueForKey:(NSString *)kABPersonAddressStateKey];
100 if(state != nil)
101 textView.text = [textView.text stringByAppendingFormat:@"省:%@\n",state];
102 NSString* street = [personaddress valueForKey:(NSString *)kABPersonAddressStreetKey];
103 if(street != nil)
104 textView.text = [textView.text stringByAppendingFormat:@"街道:%@\n",street];
105 NSString* zip = [personaddress valueForKey:(NSString *)kABPersonAddressZIPKey];
106 if(zip != nil)
107 textView.text = [textView.text stringByAppendingFormat:@"邮编:%@\n",zip];
108 NSString* coutntrycode = [personaddress valueForKey:(NSString *)kABPersonAddressCountryCodeKey];
109 if(coutntrycode != nil)
110 textView.text = [textView.text stringByAppendingFormat:@"国家编号:%@\n",coutntrycode];
111 }
112
113 //获取dates多值
114 ABMultiValueRef dates = ABRecordCopyValue(person, kABPersonDateProperty);
115 int datescount = ABMultiValueGetCount(dates);
116 for (int y = 0; y < datescount; y++)
117 {
118 //获取dates Label
119 NSString* datesLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates, y));
120 //获取dates值
121 NSString* datesContent = (NSString*)ABMultiValueCopyValueAtIndex(dates, y);
122 textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",datesLabel,datesContent];
123 }
124 //获取kind值
125 CFNumberRef recordType = ABRecordCopyValue(person, kABPersonKindProperty);
126 if (recordType == kABPersonKindOrganization) {
127 // it's a company
128 NSLog(@"it's a company\n");
129 } else {
130 // it's a person, resource, or room
131 NSLog(@"it's a person, resource, or room\n");
132 }
133
134
135 //获取IM多值
136 ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty);
137 for (int l = 1; l < ABMultiValueGetCount(instantMessage); l++)
138 {
139 //获取IM Label
140 NSString* instantMessageLabel = (NSString*)ABMultiValueCopyLabelAtIndex(instantMessage, l);
141 textView.text = [textView.text stringByAppendingFormat:@"%@\n",instantMessageLabel];
142 //获取該label下的2属性
143 NSDictionary* instantMessageContent =(NSDictionary*) ABMultiValueCopyValueAtIndex(instantMessage, l);
144 NSString* username = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageUsernameKey];
145 if(username != nil)
146 textView.text = [textView.text stringByAppendingFormat:@"username:%@\n",username];
147
148 NSString* service = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageServiceKey];
149 if(service != nil)
150 textView.text = [textView.text stringByAppendingFormat:@"service:%@\n",service];
151 }
152
153 //读取电话多值
154 ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);
155 for (int k = 0; k<ABMultiValueGetCount(phone); k++)
156 {
157 //获取电话Label
158 NSString * personPhoneLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phone, k));
159 //获取該Label下的电话值
160 NSString * personPhone = (NSString*)ABMultiValueCopyValueAtIndex(phone, k);
161
162 textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",personPhoneLabel,personPhone];
163 }
164
165 //获取URL多值
166 ABMultiValueRef url = ABRecordCopyValue(person, kABPersonURLProperty);
167 for (int m = 0; m < ABMultiValueGetCount(url); m++)
168 {
169 //获取电话Label
170 NSString * urlLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(url, m));
171 //获取該Label下的电话值
172 NSString * urlContent = (NSString*)ABMultiValueCopyValueAtIndex(url,m);
173
174 textView.text = [textView.text stringByAppendingFormat:@"%@:%@\n",urlLabel,urlContent];
175 }
176
177 //读取照片
178 NSData *image = (NSData*)ABPersonCopyImageData(person);
179
180
181 UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(200, 0, 50, 50)];
182 [myImage setImage:[UIImage imageWithData:image]];
183 myImage.opaque = YES;
184 [textView addSubview:myImage];
185
186
187
188 }
189
190 CFRelease(results);
191 CFRelease(addressBook);
192
193 复制代码

iOS 获取通讯录中联系人的所有属性 by - zfqj的更多相关文章

  1. ios 获得通讯录中联系人的所有属性 亲测,可行 兼容io6 和 ios 7

    //获取通讯录中的所有属性,并存储在 textView 中,已检验,切实可行.兼容io6 和 ios 7 ,而且ios7还没有权限确认提示. -(void)getAddressBook { ABAdd ...

  2. iOS 获得通讯录中联系人的所有属性--b

    ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef results = ABAddressBookCopyArrayOfA ...

  3. IOS 获得通讯录中联系人的所有属性 备用参考

    ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef results = ABAddressBookCopyArrayOfA ...

  4. IOS 获取通讯录中信息

    获取通讯录中信息 一. 我们设置一个ABAddressBookRef类型的属性addressBook. 二. 要获得通讯录中的信息,我们需要获取访问通讯录的权限. 在运行下面的获取权限的方法的时候,系 ...

  5. iOS获取通讯录所有联系人信息

    以下是2种方式: 第一种方法: GetAddressBook.h #import <Foundation/Foundation.h> @interface GetAddressBook : ...

  6. ios 获取通讯录的所有信息

    iOS获取通讯录全部信息 ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef results = ABAddressBoo ...

  7. iOS 获取通讯录里边的电话号码AddressBook

    1  首先导入库 <AddressBook/AddressBook.h> 2 然后在导入#import <AddressBook/AddressBook.h>文件 3 声明   ...

  8. iOS 获取通讯录权限的时机

    建议将获取通讯录权限的代码放到 -(void)viewDidAppear:(BOOL)animated 或 -(void)viewWillAppear:(BOOL)animated 假如放在 view ...

  9. 【实用篇】获取Android通讯录中联系人信息

    第一步,在Main.xml布局文件中声明一个Button控件,布局文件代码如下: <LinearLayout xmlns:android="http://schemas.android ...

随机推荐

  1. MySQL数据操作与查询笔记 • 【第4章 SELECT 数据查询】

    全部章节   >>>> 本章目录 4.1 select 选择列表 4.1.1 select 基本结构 4.1.2 选择列表 4.2 MySQL 运算符 4.2.1 MySQL ...

  2. Kylin启动步骤

    Kylin本身的启动命令比较简单, 但是由于Kylin依赖的其他组件比较多, 所以把完整的启动步骤整理一下. 1.确保集群时间同步 首先查看集群中的时间是否同步 date 如果时间不一致,需要使用如下 ...

  3. 学习git&github

    详细学习视频: 链接:https://pan.baidu.com/s/1Vub3YTo7uUUuGCJUCabBRQ 提取码:6q9x 一.git基本工作流程 我们先来理解下Git 工作区.暂存区和版 ...

  4. How to run a batch file each time the computer loads Windows

    https://www.computerhope.com/issues/ch000322.htm#:~:text=Press Start%2C type Run%2C and press Enter. ...

  5. Go标准库之html/template

    html/template包实现了数据驱动的模板,用于生成可防止代码注入的安全的HTML内容.它提供了和text/template包相同的接口,Go语言中输出HTML的场景都应使用html/templ ...

  6. LINUX学习-Mysql集群-主主备份

    接着主从备份继续. 1.编辑主从服务器 vim /etc/my.cnf 在server-id下添加一句 忽略一些信息 binlog-ignore-db=mysql 2.从服务器也授权给主服务器 gra ...

  7. 主流浏览器内核、css权重

    主流浏览器及其内核: IE:trident Firefox:Gecko Google Chrome:webkit/blink Safari:webkit Opera:presto css权重 优先级大 ...

  8. 使用.NET 6开发TodoList应用(25)——实现RefreshToken

    系列导航及源代码 使用.NET 6开发TodoList应用文章索引 需求 在上一篇文章使用.NET 6开发TodoList应用(24)--实现基于JWT的Identity功能中,我们演示了如何使用.N ...

  9. 端口状态 LISTENING、ESTABLISHED、TIME_WAIT及CLOSE_WAIT详解,以及三次握手四次挥手,滑动窗口(整理转发)

    网上查了一下端口状态的资料,我下面总结了一下,自己学习学习: TCP状态转移要点 TCP协议规定,对于已经建立的连接,网络双方要进行四次握手才能成功断开连接,如果缺少了其中某个步骤,将会使连接处于假死 ...

  10. 闯祸了,生成环境执行了DDL操作《死磕MySQL系列 十四》

    由于业务随着时间不停的改变,起初的表结构设计已经满足不了如今的需求,这时你是不是想那就加字段呗!加字段也是个艺术活,接下来由本文的主人咔咔给你吹. 试想一下这个场景 事务A在执行一个非常大的查询 事务 ...