首页 > 代码库 > 读取iPhone中的通讯录信息
读取iPhone中的通讯录信息
添加AddressBook这个包;
然后#import <AddressBook/AddressBook.h>
//取得本地通信录名柄 ABAddressBookRef addressBook; if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0){ addressBook = ABAddressBookCreateWithOptions(NULL, NULL); //等待同意后 向下执行 dispatch_semaphore_t sema = dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) { dispatch_semaphore_signal(sema); }); dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); }else{ addressBook = ABAddressBookCreate(); } //取得本地所有联系人信息 CFArrayRef results = ABAddressBookCopyArrayOfAllPeople(addressBook); for(int i = 0; i < CFArrayGetCount(results); i++){ ABRecordRef person = CFArrayGetValueAtIndex(results, i); //读取firstname NSString *firstName = (__bridge NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty); //读取lastname NSString *lastName = (__bridge NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty); //读取电话号码 NSString *phoneNum; ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty); for (int k = 0; k < ABMultiValueGetCount(phone); k++){ phoneNum = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phone, k); } NSLog(@"firstName:%@ - lastName:%@ - phoneNum:%@",firstName,lastName,phoneNum); }
读取iPhone中的通讯录信息
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。