博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios 获得通讯录中联系人的所有属性 亲测,可行 兼容io6 和 ios 7
阅读量:5990 次
发布时间:2019-06-20

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

hot3.png

//获取通讯录中的所有属性,并存储在 textView 中,已检验,切实可行。兼容io6 和 ios 7 ,而且ios7还没有权限确认提示。
-()getAddressBook{    ABAddressBookRef addressBook = ABAddressBookCreate();        CFArrayRef results = ABAddressBookCopyArrayOfAllPeople(addressBook);        ( i = ; i < CFArrayGetCount(results); i++)    {        ABRecordRef person = CFArrayGetValueAtIndex(results, i);                NSString *personName = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);        (personName != nil)            textView.text = [textView.text stringByAppendingFormat:,personName];                NSString *lastname = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);        (lastname != nil)            textView.text = [textView.text stringByAppendingFormat:,lastname];                NSString *middlename = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNameProperty);        (middlename != nil)            textView.text = [textView.text stringByAppendingFormat:,middlename];                NSString *prefix = (NSString*)ABRecordCopyValue(person, kABPersonPrefixProperty);        (prefix != nil)            textView.text = [textView.text stringByAppendingFormat:,prefix];                NSString *suffix = (NSString*)ABRecordCopyValue(person, kABPersonSuffixProperty);        (suffix != nil)            textView.text = [textView.text stringByAppendingFormat:,suffix];                NSString *nickname = (NSString*)ABRecordCopyValue(person, kABPersonNicknameProperty);        (nickname != nil)            textView.text = [textView.text stringByAppendingFormat:,nickname];                NSString *firstnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonFirstNamePhoneticProperty);        (firstnamePhonetic != nil)            textView.text = [textView.text stringByAppendingFormat:,firstnamePhonetic];                NSString *lastnamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonLastNamePhoneticProperty);        (lastnamePhonetic != nil)            textView.text = [textView.text stringByAppendingFormat:,lastnamePhonetic];                NSString *middlenamePhonetic = (NSString*)ABRecordCopyValue(person, kABPersonMiddleNamePhoneticProperty);        (middlenamePhonetic != nil)            textView.text = [textView.text stringByAppendingFormat:,middlenamePhonetic];                NSString *organization = (NSString*)ABRecordCopyValue(person, kABPersonOrganizationProperty);        (organization != nil)            textView.text = [textView.text stringByAppendingFormat:,organization];                NSString *jobtitle = (NSString*)ABRecordCopyValue(person, kABPersonJobTitleProperty);        (jobtitle != nil)            textView.text = [textView.text stringByAppendingFormat:,jobtitle];                NSString *department = (NSString*)ABRecordCopyValue(person, kABPersonDepartmentProperty);        (department != nil)            textView.text = [textView.text stringByAppendingFormat:,department];                NSDate *birthday = (NSDate*)ABRecordCopyValue(person, kABPersonBirthdayProperty);        (birthday != nil)            textView.text = [textView.text stringByAppendingFormat:,birthday];                NSString *note = (NSString*)ABRecordCopyValue(person, kABPersonNoteProperty);        (note != nil)            textView.text = [textView.text stringByAppendingFormat:,note];                NSString *firstknow = (NSString*)ABRecordCopyValue(person, kABPersonCreationDateProperty);        NSLog(,firstknow);                NSString *lastknow = (NSString*)ABRecordCopyValue(person, kABPersonModificationDateProperty);        NSLog(,lastknow);                        ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty);         emailcount = ABMultiValueGetCount(email);         ( x = ; x < emailcount; x++)        {                        NSString* emailLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(email, x));                        NSString* emailContent = (NSString*)ABMultiValueCopyValueAtIndex(email, x);            textView.text = [textView.text stringByAppendingFormat:,emailLabel,emailContent];        }                ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty);         count = ABMultiValueGetCount(address);                ( j = ; j < count; j++)        {                        NSString* addressLabel = (NSString*)ABMultiValueCopyLabelAtIndex(address, j);            textView.text = [textView.text stringByAppendingFormat:,addressLabel];                        NSDictionary* personaddress =(NSDictionary*) ABMultiValueCopyValueAtIndex(address, j);            NSString* country = [personaddress valueForKey:(NSString *)kABPersonAddressCountryKey];            (country != nil)                textView.text = [textView.text stringByAppendingFormat:,country];            NSString* city = [personaddress valueForKey:(NSString *)kABPersonAddressCityKey];            (city != nil)                textView.text = [textView.text stringByAppendingFormat:,city];            NSString* state = [personaddress valueForKey:(NSString *)kABPersonAddressStateKey];            (state != nil)                textView.text = [textView.text stringByAppendingFormat:,state];            NSString* street = [personaddress valueForKey:(NSString *)kABPersonAddressStreetKey];            (street != nil)                textView.text = [textView.text stringByAppendingFormat:,street];            NSString* zip = [personaddress valueForKey:(NSString *)kABPersonAddressZIPKey];            (zip != nil)                textView.text = [textView.text stringByAppendingFormat:,zip];            NSString* coutntrycode = [personaddress valueForKey:(NSString *)kABPersonAddressCountryCodeKey];            (coutntrycode != nil)                textView.text = [textView.text stringByAppendingFormat:,coutntrycode];        }                        ABMultiValueRef dates = ABRecordCopyValue(person, kABPersonDateProperty);         datescount = ABMultiValueGetCount(dates);         ( y = ; y < datescount; y++)        {                        NSString* datesLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(dates, y));                        NSString* datesContent = (NSString*)ABMultiValueCopyValueAtIndex(dates, y);            textView.text = [textView.text stringByAppendingFormat:,datesLabel,datesContent];        }                CFNumberRef recordType = ABRecordCopyValue(person, kABPersonKindProperty);         (recordType == kABPersonKindOrganization) {                        NSLog();        }  {                        NSLog();        }                                ABMultiValueRef instantMessage = ABRecordCopyValue(person, kABPersonInstantMessageProperty);         ( l = ; l < ABMultiValueGetCount(instantMessage); l++)        {                        NSString* instantMessageLabel = (NSString*)ABMultiValueCopyLabelAtIndex(instantMessage, l);            textView.text = [textView.text stringByAppendingFormat:,instantMessageLabel];                        NSDictionary* instantMessageContent =(NSDictionary*) ABMultiValueCopyValueAtIndex(instantMessage, l);            NSString* username = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageUsernameKey];            (username != nil)                textView.text = [textView.text stringByAppendingFormat:,username];                        NSString* service = [instantMessageContent valueForKey:(NSString *)kABPersonInstantMessageServiceKey];            (service != nil)                textView.text = [textView.text stringByAppendingFormat:,service];        }                        ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty);         ( k = ; k
< ABMultiValueGetCount(url); m++)        {                        NSString * urlLabel = (NSString*)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(url, m));                        NSString * urlContent = (NSString*)ABMultiValueCopyValueAtIndex(url,m);                        textView.text = [textView.text stringByAppendingFormat:,urlLabel,urlContent];        }                        NSData *image = (NSData*)ABPersonCopyImageData(person);                        UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];        [myImage setImage:[UIImage imageWithData:image]];        myImage.opaque = YES;        [textView addSubview:myImage];    }        CFRelease(results);    CFRelease(addressBook);}

转载于:https://my.oschina.net/u/2559341/blog/596852

你可能感兴趣的文章
Android开发13——内容提供者ContentProvider的基本使用
查看>>
基于CentOS6.5的drbd的安装与配置
查看>>
AWK高端功能-数组
查看>>
python计算春节倒计时
查看>>
前些日子联想大y终于到手
查看>>
杂志客户端阅读体验
查看>>
Linux学习之文件管理与权限了解
查看>>
Hyper-V 2016 系列教程12 Hyper-V 体系结构
查看>>
本地连接和ADSL连接
查看>>
分页查询算法实践
查看>>
系统经常处在更新状态怎么办?
查看>>
iptables防火墙详解(三)规则的导出、导入以及编写防火墙脚本
查看>>
在JSP中使用Log4j
查看>>
((uchar*)(Img1->imageData + Img1->widthStep*pt.y))[pt.x] 的 具体含义
查看>>
删除本地管理员组中除Administrator以外的用户
查看>>
ubuntu安装与测试hadoop1.1.0版本
查看>>
Eclipse下Maven工程多模块继承和聚合的创建
查看>>
CCNA(Stand-ALONE)Lab 25-Frame Relay Hub-and-Spoke Topology
查看>>
漫谈IBM Power VM历史及其特点
查看>>
Cocos Creator开发中的按钮节点的事件处理方法
查看>>