(1)第一步,引入“AddressBook.framework”库。
(2)引用“#import <AddressBook/AddressBook.h>”
(3)加入下面代码(在网上找的一些代码在xcode4.2中会报错,稍加了点修改)
ABAddressBookRef addressBook = ABAddressBookCreate(); NSMutableArray* personArray = [[[NSMutableArray alloc] init] autorelease]; personArray = (NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); NSString *firstName, *lastName, *fullName; NSLog(@"[personArray count]%d",[personArray count]); for (int i=0; i<[personArray count]; i++){ id *person = [personArray objectAtIndex:i]; 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); } }
打印结果如下,当然还有一些别的功能就不一一说了,网上多得是,只是网上的一些程序会报错,此处记起来给跟我一样的菜鸟指引下!