ios 开发,通讯录信息调用常用方法,这个比较全,不用再整理了

简介:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
ABAddressBookRef addressBook = ABAddressBookCreate();
 
     CFArrayRef results = ABAddressBookCopyArrayOfAllPeople(addressBook);
     
     for ( int  i = 0; 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, kABPers*****uffixProperty);
         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 = 0; 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 = 0; 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 = 0; 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 = 1; 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 = 0; 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 = 0; 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(200, 0, 50, 50)];
         [myImage setImage:[UIImage imageWithData:image]];
         myImage.opaque =  YES ;
         [textView addSubview:myImage];
         
 
     
     }
     
     CFRelease(results);
     CFRelease(addressBook);

 



本文转自夏雪冬日博客园博客,原文链接:http://www.cnblogs.com/heyonggang/p/3472867.html,如需转载请自行联系原作者

目录
相关文章
|
10月前
|
运维 iOS开发 Windows
windows电脑备案ios APP获取公钥和证书指纹Sha-1值的方法
在阿里云进行APP备案、在备案IOS端的环节的时候,发现需要我们将p12证书安装在电脑上,再用xcode或或钥匙串访问来获取这个证书的公钥和sha-1值。 但是大部分开发uniapp应用的同学们,或者进行发布的运维人员的电脑都是windows,无法按照阿里云的教程来获取ios的公钥和sha-1。备案就被卡主了。 这里介绍下另一个方法,就是使用香蕉云编来在线上传证书获取。如下图所示,打开香蕉云编后,找到下图这个功能
1363 0
|
iOS开发 开发者
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
1026 67
uniapp开发ios打包Error code = -5000 Error message: Error: certificate file(p12) import failed!报错问题如何解决
|
JavaScript 搜索推荐 Android开发
【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
689 8
【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
|
存储 监控 API
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
1941 11
|
iOS开发 开发者 Windows
uniapp云打包ios应用证书的获取方法,生成指南
打包用到的一共两个文件,一个是p12格式的私钥证书,一个是证书profile文件。其中生成p12证书的时候,按照官网的教程,是需要MAC电脑来协助做的,主要是生成一些csr文件和导出p12证书等。其实这些步骤也可以借助一些其他的工具来实现,不一定使用mac电脑,用windows电脑也可以创建。
1638 0
|
人工智能 程序员 API
iOS|记一名 iOS 开发新手的前两次 App 审核经历
啥,这玩意也有新手保护期?
538 0
|
物联网 Android开发 iOS开发
iOS开发 - 蓝牙学习的总结
iOS开发 - 蓝牙学习的总结
430 0
|
iOS开发
IOS开发---菜鸟学习之路--(九)-利用PullingRefreshTableView实现下拉刷新
本章主要讲解如何利用PullingRefreshTableView实现下拉(上拉)刷新的操作  PullingRefreshTableView 实现上下拉刷新的例子百度有很多,大家可以自己搜索下,先看下那些例子(一般搜索过来的都是一样的大家反正先把那部分内容先了解一下,然后再看本文档比较好。
1052 0
|
iOS开发 Android开发 存储
IOS开发---菜鸟学习之路--(十)-实现新闻详细信息浏览页面
前面已经将了上下拉刷新 实现了上下拉刷新后我们的第一级界面就做好,接下来我们就需要实现 新闻详细信息浏览了 我个人认为一般实现新闻详细页面的方法有两种(主要是数据源的不同导致了方法的不同) 第一种是本身新闻就是一个链接地址,同时是已经处理好的适应手机浏览的网页 对于这种类型的数据源,我们直接在页面中放一个WebView控件,然后将URL传递过去就好了 另一种则是普通的包含标题、时间、内容、图片等数据结构的新闻内容(我们要实现的也是这种新闻,因为实现了这种之后, 我们就可以实现任何自定义的详细信息的页面了。
1076 0
|
iOS开发
IOS开发---菜鸟学习之路--(十一)-使新闻内容自适应高度
上一章当中,我们留了一个小BUG。 其实就是浏览新闻的时候,如果文字内容过长的花,UITextView 会有个下拉框,而最底层的UIScrollView也有个下拉框,那么在使用的时候就会非常的不爽。 而这章呢我们就要解决这样一个问题了 其实并不是很复杂的修改方法 我们只需要将viewDidL...
1032 0