• 读取通讯录信息


    -(void)ReadAllPeoples

    {

        

        //取得本地通信录名柄

        

        ABAddressBookRef tmpAddressBook = nil;

        

        if ([[UIDevicecurrentDevice].systemVersionfloatValue]>=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 = (__bridgeNSArray*)ABAddressBookCopyArrayOfAllPeople(tmpAddressBook);

        

        for(id tmpPerson in tmpPeoples)

            

        {

            

            //获取的联系人单一属性:First name

            

            NSString* tmpFirstName = (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonFirstNameProperty);

            

            NSLog(@"First name:%@", tmpFirstName);

            

            

            //获取的联系人单一属性:Last name

            

            NSString* tmpLastName = (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonLastNameProperty);

            

            NSLog(@"Last name:%@", tmpLastName);

            

            

            //获取的联系人单一属性:Nickname

            

            NSString* tmpNickname = (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonNicknameProperty);

            

            NSLog(@"Nickname:%@", tmpNickname);

            

        

            

            //获取的联系人单一属性:Company name

            

            NSString* tmpCompanyname = (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonOrganizationProperty);

            

            NSLog(@"Company name:%@", tmpCompanyname);

            

            

            //获取的联系人单一属性:Job Title

            

            NSString* tmpJobTitle= (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonJobTitleProperty);

            

            NSLog(@"Job Title:%@", tmpJobTitle);

            

            

            //获取的联系人单一属性:Department name

            

            NSString* tmpDepartmentName = (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonDepartmentProperty);

            

            NSLog(@"Department name:%@", tmpDepartmentName);

            

            

            //获取的联系人单一属性:Email(s)

            

            ABMultiValueRef tmpEmails = ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonEmailProperty);

            

            for(NSInteger j = 0; ABMultiValueGetCount(tmpEmails); j++)

                

            {

                

                NSString* tmpEmailIndex = (__bridge NSString*)ABMultiValueCopyValueAtIndex(tmpEmails, j);

                

                NSLog(@"Emails%d:%@", j, tmpEmailIndex);

              

                

            }

            

            CFRelease(tmpEmails);

            

            //获取的联系人单一属性:Birthday

            

            NSDate* tmpBirthday = (__bridgeNSDate*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonBirthdayProperty);

            

            NSLog(@"Birthday:%@", tmpBirthday);

            

            

            //获取的联系人单一属性:Note

            

            NSString* tmpNote = (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonNoteProperty);

            

            NSLog(@"Note:%@", tmpNote);

         

            

            //获取的联系人单一属性:Generic phone number

            

            ABMultiValueRef tmpPhones = ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonPhoneProperty);

            

            for(NSInteger j = 0; j < ABMultiValueGetCount(tmpPhones); j++)

                

            {

                

                NSString* tmpPhoneIndex = (__bridge NSString*)ABMultiValueCopyValueAtIndex(tmpPhones, j);

                

                NSLog(@"tmpPhoneIndex%d:%@", j, tmpPhoneIndex);

                

            }

            

            CFRelease(tmpPhones);

            

        }

        

        CFRelease(tmpAddressBook);

        

    }

  • 相关阅读:
    Struts2 HelloWorld_1
    Java Web JavaMail 邮件发送
    Struts2 ActionWildcard(通配符配置)约定优于配置
    Struts2 Action
    Struts2 struts2简介
    Struts2 ActionMethod DMI(动态方法调用)
    Java Web Servlet过滤器
    com学习笔记(2)基本的com接口QueryInterface的实现
    com学习笔记(4)动态链接
    silverlight Visifire图表转图片偷天换日的做法
  • 原文地址:https://www.cnblogs.com/wudan7/p/3723337.html
Copyright © 2020-2023  润新知