//读取所有联系人
-(void)ReadAllPeoples
{
//取得本地通信录名柄
ABAddressBookRef tmpAddressBook =
ABAddressBookCreate();
//取得本地所有联系人记录
NSArray* tmpPeoples = (NSArray*)ABAddressBookCopyArrayOfAllPeople(tmpAddressBook);
for(id tmpPerson
in tmpPeoples)
{
AddressList *item = [[AddressList
alloc]init];
//获取的联系人单一属性:First name
NSString* tmpFirstName = (NSString*)ABRecordCopyValue(tmpPerson,
kABPersonFirstNameProperty);
NSLog(@"First name:%@", tmpFirstName);
//获取的联系人单一属性:Last name
NSString* tmpLastName = (NSString*)ABRecordCopyValue(tmpPerson,
kABPersonLastNameProperty);
NSLog(@"Last name:%@", tmpLastName);
item.name = [NSString
stringWithFormat:@"%@%@",tmpLastName,tmpFirstName];
//获取的联系人单一属性:Generic phone number
ABMultiValueRef tmpPhones =
ABRecordCopyValue(tmpPerson,
kABPersonPhoneProperty);
for(NSInteger j =
0; j < ABMultiValueGetCount(tmpPhones); j++)
{
NSString* tmpPhoneIndex = (NSString*)ABMultiValueCopyValueAtIndex(tmpPhones, j);
NSLog(@"tmpPhoneIndex%d:%@", j, tmpPhoneIndex);
}
item.phone = tmpPhones;
[dataArray
addObject:item];
[tmpFirstName
release];
[tmpLastName
release];
CFRelease(tmpPhones);
}
//释放内存
[tmpPeoples
release];
CFRelease(tmpAddressBook);
}