大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要介绍了ios如何实现通讯录联系人各属性获取,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
成都地区优秀IDC服务器托管提供商(创新互联).为客户提供专业的雅安机房托管,四川各地服务器托管,雅安机房托管、多线服务器托管.托管咨询专线:18982081108ABAddressBookRef 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)
label.text = [label.text stringByAppendingFormat:@"姓名:%@",personName];
//读取lastname
NSString *lastname = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
if(lastname != nil)
label.text = [label.text stringByAppendingFormat:@"%@",lastname];
//读取middlename
NSString *middlename = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty);
if(middlename != nil)
label.text = [label.text stringByAppendingFormat:@"%@",middlename];
//读取prefix前缀
NSString *prefix = (NSString*)ABRecordCopyValue(person, kABPersonPrefixProperty);
if(prefix != nil)
label.text = [label.text stringByAppendingFormat:@"%@",prefix];
//读取suffix后缀
NSString *suffix = (NSString*)ABRecordCopyValue(person, kABPersonSuffixProperty);
if(suffix != nil)
label.text = [label.text stringByAppendingFormat:@"%@",suffix];
//读取nickname呢称
NSString *nickname = (NSString*)ABRecordCopyValue(person, kABPersonNicknameProperty);
if(nickname != nil)
label.text = [label.text stringByAppendingFormat:@"%@",nickname];
//读取firstname拼音音标
NSString *firstnamePhonetic = (NSString*)ABRecordCopyValue(person,kABPersonFirstNamePhoneticProperty);
if(firstnamePhonetic != nil)
label.text = [label.text stringByAppendingFormat:@"%@",firstnamePhonetic];
//读取lastname拼音音标
NSString *lastnamePhonetic = (NSString*)ABRecordCopyValue(person,kABPersonLastNamePhoneticProperty);
if(lastnamePhonetic != nil)
label.text = [label.text stringByAppendingFormat:@"%@",lastnamePhonetic];
//读取middlename拼音音标
NSString *middlenamePhonetic = (NSString*)ABRecordCopyValue(person,kABPersonMiddleNamePhoneticProperty);
if(middlenamePhonetic != nil)
label.text = [label.text stringByAppendingFormat:@"%@",middlenamePhonetic];
//读取organization公司
NSString *organization = (NSString*)ABRecordCopyValue(person, kABPersonOrganizationProperty);
if(organization != nil)
label.text = [label.text stringByAppendingFormat:@"%@",organization];
//读取jobtitle工作
NSString *jobtitle = (NSString*)ABRecordCopyValue(person, kABPersonJobTitleProperty);
if(jobtitle != nil)
label.text = [label.text stringByAppendingFormat:@"%@",jobtitle];
//读取department部门
NSString *department = (NSString*)ABRecordCopyValue(person, kABPersonDepartmentProperty);
if(department != nil)
label.text = [label.text stringByAppendingFormat:@"%@",department];
//读取birthday生日
NSDate *birthday = (NSDate*)ABRecordCopyValue(person, kABPersonBirthdayProperty);
if(birthday != nil)
label.text = [label.text stringByAppendingFormat:@"%@",birthday];
//读取note备忘录
NSString *note = (NSString*)ABRecordCopyValue(person, kABPersonNoteProperty);
if(note != nil)
label.text = [label.text stringByAppendingFormat:@"%@",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);
label.text = [label.text stringByAppendingFormat:@"%@:%@",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);
label.text = [label.text stringByAppendingFormat:@"%@",addressLabel];
//获取該label下的地址6属性
NSDictionary* personaddress =(NSDictionary*) ABMultiValueCopyValueAtIndex(address, j);
NSString* country = [personaddress valueForKey:(NSString *)kABPersonAddressCountryKey];
if(country != nil)
label.text = [label.text stringByAppendingFormat:@"国家:%@",country];
NSString* city = [personaddress valueForKey:(NSString *)kABPersonAddressCityKey];
if(city != nil)
label.text = [label.text stringByAppendingFormat:@"城市:%@",city];
NSString* state = [personaddress valueForKey:(NSString *)kABPersonAddressStateKey];
if(state != nil)
label.text = [label.text stringByAppendingFormat:@"省:%@",state];
NSString* street = [personaddress valueForKey:(NSString *)kABPersonAddressStreetKey];
if(street != nil)
label.text = [label.text stringByAppendingFormat:@"街道:%@",street];
NSString* zip = [personaddress valueForKey:(NSString *)kABPersonAddressZIPKey];
if(zip != nil)
label.text = [label.text stringByAppendingFormat:@"邮编:%@",zip];
NSString* coutntrycode = [personaddress valueForKey:(NSString*)kABPersonAddressCountryCodeKey];
if(coutntrycode != nil)
label.text = [label.text stringByAppendingFormat:@"国家编号:%@",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);
label.text = [label.text stringByAppendingFormat:@"%@:%@",datesLabel,datesContent];
}
//获取kind值
CFNumberRef recordType = ABRecordCopyValue(person, kABPersonKindProperty);
if (recordType == kABPersonKindOrganization) {
// it's a company
NSLog(@"it's a company");
} else {
// it's a person, resource, or room
NSLog(@"it's a person, resource, or room");
}
//获取IM多值
ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty);
for (int l = 1; l < ABMultiValueGetCount(instantMessage); l++)
{
//获取IM Label
NSString* instantMessageLabel = (NSString*)ABMultiValueCopyLabelAtIndex(instantMessage, l);
label.text = [label.text stringByAppendingFormat:@"%@",instantMessageLabel];
//获取該label下的2属性
NSDictionary* instantMessageContent =(NSDictionary*)ABMultiValueCopyValueAtIndex(instantMessage, l);
NSString* username = [instantMessageContent valueForKey:(NSString*)kABPersonInstantMessageUsernameKey];
if(username != nil)
label.text = [label.text stringByAppendingFormat:@"username:%@",username];
NSString* service = [instantMessageContent valueForKey:(NSString*)kABPersonInstantMessageServiceKey];
if(service != nil)
label.text = [label.text stringByAppendingFormat:@"service:%@",service];
}
//读取电话多值
ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);
for (int k = 0; k { //获取电话Label NSString * personPhoneLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(phone, k)); //获取該Label下的电话值 NSString * personPhone = (NSString*)ABMultiValueCopyValueAtIndex(phone, k); label.text = [label.text stringByAppendingFormat:@"%@:%@",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); label.text = [label.text stringByAppendingFormat:@"%@:%@",urlLabel,urlContent]; } //读取照片 NSData *p_w_picpath = (NSData*)ABPersonCopyImageData(person); UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(200, 0, 50, 50)]; [myImage setImage:[UIImage p_w_picpathWithData:p_w_picpath]]; myImage.opaque = YES; [label addSubview:myImage]; } //CF类型变量不适用ARC,需要释放 CFRelease(results); CFRelease(addressBook); 感谢你能够认真阅读完这篇文章,希望小编分享的“ios如何实现通讯录联系人各属性获取”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习! 另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网页题目:ios如何实现通讯录联系人各属性获取-创新互联
转载来源:http://dzwzjz.com/article/dpiijc.html