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,如需转载请自行联系原作者

目录
相关文章
|
2天前
|
设计模式 前端开发 Swift
探索iOS开发:从初级到高级的旅程
【10月更文挑战第31天】在这篇文章中,我们将一起踏上iOS开发的旅程。无论你是初学者还是有经验的开发者,这篇文章都将为你提供有价值的信息和技巧。我们将从基础开始,逐步深入到更高级的技术和概念。让我们一起探索iOS开发的世界吧!
|
5天前
|
设计模式 前端开发 Swift
探索iOS开发:从初级到高级的旅程
【10月更文挑战第28天】在这篇技术性文章中,我们将一起踏上一段探索iOS开发的旅程。无论你是刚入门的新手,还是希望提升技能的开发者,这篇文章都将为你提供宝贵的指导和灵感。我们将从基础概念开始,逐步深入到高级主题,如设计模式、性能优化等。通过阅读这篇文章,你将获得一个清晰的学习路径,帮助你在iOS开发领域不断成长。
30 2
|
11天前
|
安全 API Swift
探索iOS开发中的Swift语言之美
【10月更文挑战第23天】在数字时代的浪潮中,iOS开发如同一艘航船,而Swift语言则是推动这艘船前进的风帆。本文将带你领略Swift的独特魅力,从语法到设计哲学,再到实际应用案例,我们将一步步深入这个现代编程语言的世界。你将发现,Swift不仅仅是一种编程语言,它是苹果生态系统中的一个创新工具,它让iOS开发变得更加高效、安全和有趣。让我们一起启航,探索Swift的奥秘,感受编程的乐趣。
|
13天前
|
Swift iOS开发 开发者
探索iOS开发中的SwiftUI框架
【10月更文挑战第21天】在苹果生态系统中,SwiftUI的引入无疑为iOS应用开发带来了革命性的变化。本文将通过深入浅出的方式,带领读者了解SwiftUI的基本概念、核心优势以及如何在实际项目中运用这一框架。我们将从一个简单的例子开始,逐步深入到更复杂的应用场景,让初学者能够快速上手,同时也为有经验的开发者提供一些深度使用的技巧和策略。
37 1
|
1天前
|
存储 数据可视化 Swift
探索iOS开发之旅:从新手到专家
【10月更文挑战第33天】在这篇文章中,我们将一起踏上一场激动人心的iOS开发之旅。无论你是刚刚入门的新手,还是已经有一定经验的开发者,这篇文章都将为你提供宝贵的知识和技能。我们将从基础的iOS开发概念开始,逐步深入到更复杂的主题,如用户界面设计、数据存储和网络编程等。通过阅读这篇文章,你将获得成为一名优秀iOS开发者所需的全面技能和知识。让我们一起开始吧!
|
2天前
|
移动开发 Java Android开发
探索Android与iOS开发的差异性与互联性
【10月更文挑战第32天】在移动开发的大潮中,Android和iOS两大平台各领风骚。本文将深入浅出地探讨这两个平台的开发差异,并通过实际代码示例,展示如何在各自平台上实现相似的功能。我们将从开发环境、编程语言、用户界面设计、性能优化等多个角度进行对比分析,旨在为开发者提供跨平台开发的实用指南。
18 0
|
29天前
|
Android开发 Swift iOS开发
探索安卓与iOS开发的差异:从代码到用户体验
【10月更文挑战第5天】在移动应用开发的广阔天地中,安卓和iOS两大平台各占半壁江山。它们在技术架构、开发环境及用户体验上有着根本的不同。本文通过比较这两种平台的开发过程,揭示背后的设计理念和技术选择如何影响最终产品。我们将深入探讨各自平台的代码示例,理解开发者面临的挑战,以及这些差异如何塑造用户的日常体验。
|
C语言 iOS开发
iOS(CGGeometry)几何类方法总结
iOS(CGGeometry)几何类方法总结
170 0
|
iOS开发 C语言
IOS(CGGeometry)几何类方法总结
<div class="BlogAbstracts" style="margin:0px; padding:10px; color:rgb(51,51,51); font-size:14px; background-color:rgb(244,247,249); line-height:21.600000381469727px; font-family:Verdana,sans-serif
1732 0
|
30天前
|
Java Android开发 Swift
安卓与iOS开发对比:平台选择对项目成功的影响
【10月更文挑战第4天】在移动应用开发的世界中,选择合适的平台是至关重要的。本文将深入探讨安卓和iOS两大主流平台的开发环境、用户基础、市场份额和开发成本等方面的差异,并分析这些差异如何影响项目的最终成果。通过比较这两个平台的优势与挑战,开发者可以更好地决定哪个平台更适合他们的项目需求。
98 1