博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS读取通讯录
阅读量:6708 次
发布时间:2019-06-25

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

iOS读取通讯录中的各种信息

//读取所有联系人-(void)ReadAllPeoples{        //取得本地通信录名柄        ABAddressBookRef tmpAddressBook = nil;        if ([[UIDevice currentDevice].systemVersion floatValue]>=6.0) {        tmpAddressBook=ABAddressBookCreateWithOptions(NULL, NULL);        dispatch_semaphore_t sema=dispatch_semaphore_create(0);        ABAddressBookRequestAccessWithCompletion(tmpAddressBook, ^(bool greanted, CFErrorRef error){            dispatch_semaphore_signal(sema);        });                dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);    }    else    {        tmpAddressBook =ABAddressBookCreate();    }    //取得本地所有联系人记录            if (tmpAddressBook==nil) {        return ;    };    NSArray* tmpPeoples = (__bridge NSArray*)ABAddressBookCopyArrayOfAllPeople(tmpAddressBook);        for(id tmpPerson in tmpPeoples)            {                //获取的联系人单一属性:First name                NSString* tmpFirstName = (__bridge NSString*)ABRecordCopyValue((__bridge ABRecordRef)(tmpPerson), kABPersonFirstNameProperty);                NSLog(@"First name:%@", tmpFirstName);                        //获取的联系人单一属性:Last name                NSString* tmpLastName = (__bridge NSString*)ABRecordCopyValue((__bridge ABRecordRef)(tmpPerson), kABPersonLastNameProperty);                NSLog(@"Last name:%@", tmpLastName);                        //获取的联系人单一属性:Nickname                NSString* tmpNickname = (__bridge NSString*)ABRecordCopyValue((__bridge ABRecordRef)(tmpPerson), kABPersonNicknameProperty);                NSLog(@"Nickname:%@", tmpNickname);                        //获取的联系人单一属性:Company name                NSString* tmpCompanyname = (__bridge NSString*)ABRecordCopyValue((__bridge ABRecordRef)(tmpPerson), kABPersonOrganizationProperty);                NSLog(@"Company name:%@", tmpCompanyname);                        //获取的联系人单一属性:Job Title                NSString* tmpJobTitle= (__bridge NSString*)ABRecordCopyValue((__bridge ABRecordRef)(tmpPerson), kABPersonJobTitleProperty);                NSLog(@"Job Title:%@", tmpJobTitle);                        //获取的联系人单一属性:Department name                NSString* tmpDepartmentName = (__bridge NSString*)ABRecordCopyValue((__bridge ABRecordRef)(tmpPerson), kABPersonDepartmentProperty);                NSLog(@"Department name:%@", tmpDepartmentName);                        //获取的联系人单一属性:Email(s)                ABMultiValueRef tmpEmails = ABRecordCopyValue((__bridge ABRecordRef)(tmpPerson), kABPersonEmailProperty);                for(NSInteger j = 0; j < ABMultiValueGetCount(tmpEmails); j++)                    {                        NSString* tmpEmailIndex = (__bridge NSString*)ABMultiValueCopyValueAtIndex(tmpEmails, j);                        NSLog(@"Emails%ld:%@", (long)j, tmpEmailIndex);                                }                CFRelease(tmpEmails);                //获取的联系人单一属性:Birthday                NSDate* tmpBirthday = (__bridge NSDate*)ABRecordCopyValue((__bridge ABRecordRef)(tmpPerson), kABPersonBirthdayProperty);                NSLog(@"Birthday:%@", tmpBirthday);                        //获取的联系人单一属性:Note                NSString* tmpNote = (__bridge NSString*)ABRecordCopyValue((__bridge ABRecordRef)(tmpPerson), kABPersonNoteProperty);                NSLog(@"Note:%@", tmpNote);                        //获取的联系人单一属性:Generic phone number                ABMultiValueRef tmpPhones = ABRecordCopyValue((__bridge ABRecordRef)(tmpPerson), kABPersonPhoneProperty);                for(NSInteger j = 0; j < ABMultiValueGetCount(tmpPhones); j++)                    {                        NSString* tmpPhoneIndex = (__bridge NSString*)ABMultiValueCopyValueAtIndex(tmpPhones, j);                        NSLog(@"tmpPhoneIndex%ld:%@", (long)j, tmpPhoneIndex);                                }                CFRelease(tmpPhones);            }        //释放内存             CFRelease(tmpAddressBook);    }复制代码

转载地址:http://dgilo.baihongyu.com/

你可能感兴趣的文章
windows EFS加密
查看>>
那些年遇到过的面试题
查看>>
2018.1.31 8周3次课
查看>>
sublime汉化
查看>>
MyEclipse8.5注册码 到2015年
查看>>
Netfilter/iptables的一些新进展
查看>>
Linux下使用虚拟网卡的ingress流控(入口流控)
查看>>
关于Netfilter NF_HOOK宏的outdev参数bug
查看>>
VNC配置
查看>>
RIPv2与EIGRP的自动汇总区别
查看>>
python Flask w2ui sidebar json数据加载方法
查看>>
Linux查看日志定位问题
查看>>
双向实时远程同步文件(inotify+rsync与nfs)
查看>>
『MCSE 2008系统管理视频』Unit 14 文件服务器的管理
查看>>
SIM_AT_Command
查看>>
Windows-- ×××安装与配置过程
查看>>
virtualbox安装ghost版本winxp iso
查看>>
rsync生产实战考试题模拟09
查看>>
Session详解
查看>>
我的友情链接
查看>>