博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios获得通讯录中联系人的所有属性
阅读量:6441 次
发布时间:2019-06-23

本文共 8490 字,大约阅读时间需要 28 分钟。

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, kABPersonSuffixProperty);        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

转载于:https://www.cnblogs.com/516inc/archive/2012/11/05/2755380.html

你可能感兴趣的文章
openstack中虚机修复模式(类似winpe)
查看>>
lvm扩展容量大小
查看>>
关于HTTPS
查看>>
suse下配置NTP(Network Time Protocol)服务
查看>>
javascript事件冒泡机制探讨
查看>>
pxe网络装机kickstart的密码生成
查看>>
安卓Fragment的切换
查看>>
请注意不一样的innodb引擎
查看>>
Python数据类型
查看>>
Oracle查询语句的优化-记录一
查看>>
spring cloud 配置中心--本地 native
查看>>
mysql备份工具mysqldump
查看>>
Python rabbitmq的使用(三)
查看>>
负载均衡实施 应该因地制宜
查看>>
win7笔记本变路由器
查看>>
一个简单的c问题
查看>>
Linux的用户和组命令之newgrp
查看>>
FaceID或者TouchID
查看>>
我的友情链接
查看>>
Java虚拟机学习 - JDK可视化监控工具
查看>>