zoukankan      html  css  js  c++  java
  • 实现通讯录的查询与删除

    os提供了对通讯录操作的组建,其中一个是直接操作通讯录,另一个是调用通讯录的UI组建。实现方法如下:

    添加AddressBook.framework到工程中。

    image

    代码实现:

        -(IBAction)onClickbutton:(id)sender
        {
            NSMutableArray* personArray =[[[NSMutableArray alloc] init] autorelease];
            ABAddressBookRef addressBook =ABAddressBookCreate();
            NSString*firstName,*lastName,*fullName;
            personArray =(NSMutableArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
            if([sender tag]==0){
    
                for(id *person in personArray)
                {
                    firstName =(NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
                    firstName =[firstName stringByAppendingFormat:@" "];
                    lastName =(NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);   
                    fullName =[firstName stringByAppendingFormat:@"%@",lastName];
                    NSLog(@"===%@",fullName);
                    ABMultiValueRef phones =(ABMultiValueRef)ABRecordCopyValue(person, kABPersonPhoneProperty);
                    for(int i =0;i <ABMultiValueGetCount(phones); i++)
                    { 
                        NSString*phone =(NSString*)ABMultiValueCopyValueAtIndex(phones, i);
                        NSLog(@"===%@",phone);
                    }
                    ABMultiValueRef mails =(ABMultiValueRef)ABRecordCopyValue(person, kABPersonEmailProperty);
                    for(int i =0;i <ABMultiValueGetCount(mails); i++)
                    { 
                        NSString*mail =(NSString*)ABMultiValueCopyValueAtIndex(mails, i);
                        NSLog(@"==%@",mail);
                    }       
                }   
            }else{
                //删除信息
                //返回所有联系人到一个数组中
                CFArrayRef personArray =ABAddressBookCopyArrayOfAllPeople(addressBook);
                CFIndex personCount =ABAddressBookGetPersonCount(addressBook);
                  for(int i =0;i<personCount;i++){
                      ABRecordRefref=CFArrayGetValueAtIndex(personArray, i);
                      CFStringRef firstName1 =ABRecordCopyValue(ref, kABPersonFirstNameProperty);
                      CFStringRef lastName1 =ABRecordCopyValue(ref, kABPersonLastNameProperty);
                      NSString*contactFirstLast =[NSString stringWithFormat: @"%@%@",(NSString*)firstName1,(NSString*)lastName1];
                    if([contactFirstLast isEqualToString:@"徐梦"]){
                        //删除联系人
                        ABAddressBookRemoveRecord(addressBook,ref,nil);
                    }
                }
                //保存电话本
                ABAddressBookSave(addressBook,nil);  
                //释放内存
                //CFRelease(personRef);
        //        CFRelease(addressbookRef); 
            }
        }
  • 相关阅读:
    【视频】特别适合新手的运维利器ansible入门教程手册(附带视频演示和源代码)
    OSI,TCP/IP,TCP,UDP,Socket基础知识整理与回顾
    (语法基础)浅谈面向切面编程(AOP)
    Docker容器安装配置SQLServer服务(Linux)
    Asp Core部署到IIS服务器
    Tomcat:Commons Daemon procrun stdout initialized
    linux查看端口常用命令
    Linux下 Nginx安装与配置(Centos7)
    Linux下将.Asp Core 部署到 Docker容器中
    React Native Tips
  • 原文地址:https://www.cnblogs.com/q403154749/p/3928114.html
Copyright © 2011-2022 走看看