您的位置:首页 > 移动开发 > IOS开发

ios开发之获得手机通讯录中所有联系人的属性

2014-03-21 21:55 411 查看
001
ABAddressBookRefaddressBook=ABAddressBookCreate();
002
003
CFArrayRefresults=ABAddressBookCopyArrayOfAllPeople(addressBook);
004
005
for
(
int
i=0;i<CFArrayGetCount(results);i++)
006
{
007
ABRecordRefperson=CFArrayGetValueAtIndex(results,i);
008
//读取firstname
009
NSString*personName=(NSString*)ABRecordCopyValue(person,kABPersonFirstNameProperty);
010
if
(personName!=nil)
011
textView.text=[textView.textstringByAppendingFormat:@
"\n姓名:%@\n"
,personName];
012
//读取lastname
013
NSString*lastname=(NSString*)ABRecordCopyValue(person,kABPersonLastNameProperty);
014
if
(lastname!=nil)
015
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,lastname];
016
//读取middlename
017
NSString*middlename=(NSString*)ABRecordCopyValue(person,kABPersonMiddleNameProperty);
018
if
(middlename!=nil)
019
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,middlename];
020
//读取prefix前缀
021
NSString*prefix=(NSString*)ABRecordCopyValue(person,kABPersonPrefixProperty);
022
if
(prefix!=nil)
023
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,prefix];
024
//读取suffix后缀
025
NSString*suffix=(NSString*)ABRecordCopyValue(person,kABPersonSuffixProperty);
026
if
(suffix!=nil)
027
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,suffix];
028
//读取nickname呢称
029
NSString*nickname=(NSString*)ABRecordCopyValue(person,kABPersonNicknameProperty);
030
if
(nickname!=nil)
031
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,nickname];
032
//读取firstname拼音音标
033
NSString*firstnamePhonetic=(NSString*)ABRecordCopyValue(person,kABPersonFirstNamePhoneticProperty);
034
if
(firstnamePhonetic!=nil)
035
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,firstnamePhonetic];
036
//读取lastname拼音音标
037
NSString*lastnamePhonetic=(NSString*)ABRecordCopyValue(person,kABPersonLastNamePhoneticProperty);
038
if
(lastnamePhonetic!=nil)
039
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,lastnamePhonetic];
040
//读取middlename拼音音标
041
NSString*middlenamePhonetic=(NSString*)ABRecordCopyValue(person,kABPersonMiddleNamePhoneticProperty);
042
if
(middlenamePhonetic!=nil)
043
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,middlenamePhonetic];
044
//读取organization公司
045
NSString*organization=(NSString*)ABRecordCopyValue(person,kABPersonOrganizationProperty);
046
if
(organization!=nil)
047
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,organization];
048
//读取jobtitle工作
049
NSString*jobtitle=(NSString*)ABRecordCopyValue(person,kABPersonJobTitleProperty);
050
if
(jobtitle!=nil)
051
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,jobtitle];
052
//读取department部门
053
NSString*department=(NSString*)ABRecordCopyValue(person,kABPersonDepartmentProperty);
054
if
(department!=nil)
055
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,department];
056
//读取birthday生日
057
NSDate*birthday=(NSDate*)ABRecordCopyValue(person,kABPersonBirthdayProperty);
058
if
(birthday!=nil)
059
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,birthday];
060
//读取note备忘录
061
NSString*note=(NSString*)ABRecordCopyValue(person,kABPersonNoteProperty);
062
if
(note!=nil)
063
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,note];
064
//第一次添加该条记录的时间
065
NSString*firstknow=(NSString*)ABRecordCopyValue(person,kABPersonCreationDateProperty);
066
NSLog(@
"第一次添加该条记录的时间%@\n"
,firstknow);
067
//最后一次修改該条记录的时间
068
NSString*lastknow=(NSString*)ABRecordCopyValue(person,kABPersonModificationDateProperty);
069
NSLog(@
"最后一次修改該条记录的时间%@\n"
,lastknow);
070
071
//获取email多值
072
ABMultiValueRefemail=ABRecordCopyValue(person,kABPersonEmailProperty);
073
int
emailcount=ABMultiValueGetCount(email);
074
for
(
int
x=0;x<emailcount;x++)
075
{
076
//获取emailLabel
077
NSString*emailLabel=(NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(email,x));
078
//获取email值
079
NSString*emailContent=(NSString*)ABMultiValueCopyValueAtIndex(email,x);
080
textView.text=[textView.textstringByAppendingFormat:@
"%@:%@\n"
,emailLabel,emailContent];
081
}
082
//读取地址多值
083
ABMultiValueRefaddress=ABRecordCopyValue(person,kABPersonAddressProperty);
084
int
count=ABMultiValueGetCount(address);
085
086
for
(
int
j=0;j<count;j++)
087
{
088
//获取地址Label
089
NSString*addressLabel=(NSString*)ABMultiValueCopyLabelAtIndex(address,j);
090
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,addressLabel];
091
//获取該label下的地址6属性
092
NSDictionary*personaddress=(NSDictionary*)ABMultiValueCopyValueAtIndex(address,j);
093
NSString*country=[personaddressvalueForKey:(NSString*)kABPersonAddressCountryKey];
094
if
(country!=nil)
095
textView.text=[textView.textstringByAppendingFormat:@
"国家:%@\n"
,country];
096
NSString*city=[personaddressvalueForKey:(NSString*)kABPersonAddressCityKey];
097
if
(city!=nil)
098
textView.text=[textView.textstringByAppendingFormat:@
"城市:%@\n"
,city];
099
NSString*state=[personaddressvalueForKey:(NSString*)kABPersonAddressStateKey];
100
if
(state!=nil)
101
textView.text=[textView.textstringByAppendingFormat:@
"省:%@\n"
,state];
102
NSString*street=[personaddressvalueForKey:(NSString*)kABPersonAddressStreetKey];
103
if
(street!=nil)
104
textView.text=[textView.textstringByAppendingFormat:@
"街道:%@\n"
,street];
105
NSString*zip=[personaddressvalueForKey:(NSString*)kABPersonAddressZIPKey];
106
if
(zip!=nil)
107
textView.text=[textView.textstringByAppendingFormat:@
"邮编:%@\n"
,zip];
108
NSString*coutntrycode=[personaddressvalueForKey:(NSString*)kABPersonAddressCountryCodeKey];
109
if
(coutntrycode!=nil)
110
textView.text=[textView.textstringByAppendingFormat:@
"国家编号:%@\n"
,coutntrycode];
111
}
112
113
//获取dates多值
114
ABMultiValueRefdates=ABRecordCopyValue(person,kABPersonDateProperty);
115
int
datescount=ABMultiValueGetCount(dates);
116
for
(
int
y=0;y<datescount;y++)
117
{
118
//获取datesLabel
119
NSString*datesLabel=(NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates,y));
120
//获取dates值
121
NSString*datesContent=(NSString*)ABMultiValueCopyValueAtIndex(dates,y);
122
textView.text=[textView.textstringByAppendingFormat:@
"%@:%@\n"
,datesLabel,datesContent];
123
}
124
//获取kind值
125
CFNumberRefrecordType=ABRecordCopyValue(person,kABPersonKindProperty);
126
if
(recordType==kABPersonKindOrganization){
127
//it'sacompany
128
NSLog(@
"it'sacompany\n"
);
129
}
else
{
130
//it'saperson,resource,orroom
131
NSLog(@
"it'saperson,resource,orroom\n"
);
132
}
133
134
135
//获取IM多值
136
ABMultiValueRefinstantMessage=ABRecordCopyValue(person,kABPersonInstantMessageProperty);
137
for
(
int
l=1;l<ABMultiValueGetCount(instantMessage);l++)
138
{
139
//获取IMLabel
140
NSString*instantMessageLabel=(NSString*)ABMultiValueCopyLabelAtIndex(instantMessage,l);
141
textView.text=[textView.textstringByAppendingFormat:@
"%@\n"
,instantMessageLabel];
142
//获取該label下的2属性
143
NSDictionary*instantMessageContent=(NSDictionary*)ABMultiValueCopyValueAtIndex(instantMessage,l);
144
NSString*username=[instantMessageContentvalueForKey:(NSString*)kABPersonInstantMessageUsernameKey];
145
if
(username!=nil)
146
textView.text=[textView.textstringByAppendingFormat:@
"username:%@\n"
,username];
147
148
NSString*service=[instantMessageContentvalueForKey:(NSString*)kABPersonInstantMessageServiceKey];
149
if
(service!=nil)
150
textView.text=[textView.textstringByAppendingFormat:@
"service:%@\n"
,service];
151
}
152
153
//读取电话多值
154
ABMultiValueRefphone=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.textstringByAppendingFormat:@
"%@:%@\n"
,personPhoneLabel,personPhone];
163
}
164
165
//获取URL多值
166
ABMultiValueRefurl=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.textstringByAppendingFormat:@
"%@:%@\n"
,urlLabel,urlContent];
175
}
176
177
//读取照片
178
NSData*image=(NSData*)ABPersonCopyImageData(person);
179
180
181
UIImageView*myImage=[[UIImageViewalloc]initWithFrame:CGRectMake(200,0,50,50)];
182
[myImagesetImage:[UIImageimageWithData:image]];
183
myImage.opaque=YES;
184
[textViewaddSubview:myImage];
185
186
187
188
}
189
190
CFRelease(results);
191
CFRelease(addressBook);
}

更多0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: