ios实现通讯录的查询与删除
2012-12-21 15:04
423 查看
os提供了对通讯录操作的组建,其中一个是直接操作通讯录,另一个是调用通讯录的UI组建。实现方法如下:
添加AddressBook.framework到工程中。
代码实现:
添加AddressBook.framework到工程中。
代码实现:
-(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); } }
相关文章推荐
- ios实现通讯录的查询与删除
- ios实现通讯录的查询与删除
- ios实现通讯录的查询与删除
- 应用内实现 iOS 通讯录查询与删除功能的代码
- ios实现通讯录的查询与删除
- ios-day13-01(私人通讯录。控制器之间的数据传递、保存密码和自动登录的实现、普通对象的归档、UITableView的局部刷新和向左滑动删除功能等等)
- 用线性表编写通讯录管理系统 实现添加,查询,修改,删除功能
- 实现通讯录的查询与删除
- c语言版通讯录 实现联系人信息的添加,删除,修改,排序,保存,查询
- winForm中DataSet实现数据查询、保存和删除 .
- iOS UITableView划动删除的实现
- 稳扎稳打Silverlight(57) - 4.0通信之WCF RIA Services: 概述, 通过 DomainDataSource 实现数据的添加、查询、更新和删除操作
- 稳扎稳打Silverlight(57) - 4.0通信之WCF RIA Services: 概述, 通过 DomainDataSource 实现数据的添加、查询、更新和删除操作
- spring整合ehcache 注解实现查询缓存,并实现实时缓存更新或删除
- 稳扎稳打Silverlight(58) - 4.0通信之WCF RIA Services: 通过 Domain Service, 以 MVVM 模式实现数据的添加、删除、修改和查询
- lucene.net 2.9.2 实现索引生成,修改,查询,删除功
- 二叉查找树(查询、插入、遍历、删除)--Java实现
- iOS项目开发小技巧 (三) --UITableView实现Cell左划删除等自定义功能
- html+css+angularjs 实现商品库存信息管理页面 可删除/批量删除/可模糊查询/可升序降序
- Xamarin.Android 入门实例(4)之实现对 SQLLite 进行添加/修改/删除/查询操作