zoukankan      html  css  js  c++  java
  • 获取 iPhone 上联系人姓名、电话、邮件的代码

    iOS4 已经开放了查询通讯录信息的功能,下面分享一段会员cctv的获取
    iPhone 上存储的联系人姓名、电话、邮件的代码

    苹果 iPhone 是允许查询讯录信息的,这就为很多第三方通讯类应用提供了方便。下面分享一段会员“cctv”的获取 iPhone 上存储的联系人姓名、电话、邮件的代码

    + (NSMutableArray *) getAllContacts
    {
        NSMutableArray *contactsArray = [[[NSMutableArray alloc] init] autorelease];
        NSMutableArray* personArray = [[[NSMutableArray alloc] init] autorelease];
        
        ABAddressBookRef addressBook = ABAddressBookCreate();
        NSString *firstName, *lastName, *fullName;
        personArray = (NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
        
        Contacts *contact;
        for (id *person in personArray)
        {
            contact = [[Contacts alloc] init];    
            firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
            firstName = [firstName stringByAppendingFormat:@" "];
            lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);    
            fullName = [firstName stringByAppendingFormat:@"%@",lastName];
            contact.contactName = fullName;
            
            ABMultiValueRef phones = (ABMultiValueRef) ABRecordCopyValue(person, kABPersonPhoneProperty);
            for(int i = 0 ;i < ABMultiValueGetCount(phones); i++)
            {  
                NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phones, i);
                [contact.contactPhoneArray addObject:phone];
            }
            
            ABMultiValueRef mails = (ABMultiValueRef) ABRecordCopyValue(person, kABPersonEmailProperty);
            for(int i = 0 ;i < ABMultiValueGetCount(mails); i++)
            {  
                NSString *mail = (NSString *)ABMultiValueCopyValueAtIndex(mails, i);
                [contact.contactMailArray addObject:mail];
            }        
            [contactsArray addObject:contact];   // add contact into array
            [contact release];
        }    
        return contactsArray;
    }
    
  • 相关阅读:
    图片懒加载技术
    验证码处理
    基于requests模块的cookie,session和线程池爬取
    最快理解
    Golang
    Django REST framework
    Django REST framework
    Django
    Django
    搭建邮件服务器 Postfix + Dovecot (CentOS)
  • 原文地址:https://www.cnblogs.com/lm3515/p/2013729.html
Copyright © 2011-2022 走看看