//读取所有联系人
-(void)ReadAllPeoples
{
//取得本地通信录名柄
ABAddressBookRef tmpAddressBook = ABAddressBookCreate();
//取得本地所有联系人记录
NSArray* tmpPeoples = (NSArray*)ABAddressBookCopyArrayOfAllPeople(tmpAddressBook);
for(id tmpPerson in tmpPeoples)
{
//获取的联系人单一属性:First name
NSString* tmpFirstName = (NSString*)ABRecordCopyValue(tmpPerson, kABPersonFirstNameProperty);
NSLog(@"First name:%@", tmpFirstName);
[tmpFirstName release];
//获取的联系人单一属性:Last name
NSString* tmpLastName = (NSString*)ABRecordCopyValue(tmpPerson, kABPersonLastNameProperty);
NSLog(@"Last name:%@", tmpLastName);
[tmpLastName release];
//获取的联系人单一属性:Nickname
NSString* tmpNickname = (NSString*)ABRecordCopyValue(tmpPerson, kABPersonNicknameProperty);
NSLog(@"Nickname:%@", tmpNickname);
[tmpNickname release];
//获取的联系人单一属性:Company name
NSString* tmpCompanyname = (NSString*)ABRecordCopyValue(tmpPerson, kABPersonOrganizationProperty);
NSLog(@"Company name:%@", tmpCompanyname);
[tmpCompanyname release];
//获取的联系人单一属性:Job Title
NSString* tmpJobTitle= (NSString*)ABRecordCopyValue(tmpPerson, kABPersonJobTitleProperty);
NSLog(@"Job Title:%@", tmpJobTitle);
[tmpJobTitle release];
//获取的联系人单一属性:Department name
NSString* tmpDepartmentName = (NSString*)ABRecordCopyValue(tmpPerson, kABPersonDepartmentProperty);
NSLog(@"Department name:%@", tmpDepartmentName);
[tmpDepartmentName release];
//获取的联系人单一属性:Email(s)
ABMultiValueRef tmpEmails = ABRecordCopyValue(tmpPerson, kABPersonEmailProperty);
for(NSInteger j = 0; ABMultiValueGetCount(tmpEmails); j++)
{
NSString* tmpEmailIndex = (NSString*)ABMultiValueCopyValueAtIndex(tmpEmails, j);
NSLog(@"Emails%d:%@", j, tmpEmailIndex);
[tmpEmailIndex release];
}
CFRelease(tmpEmails);
//获取的联系人单一属性:Birthday
NSDate* tmpBirthday = (NSDate*)ABRecordCopyValue(tmpPerson, kABPersonBirthdayProperty);
NSLog(@"Birthday:%@", tmpBirthday);
[tmpBirthday release];
//获取的联系人单一属性:Note
NSString* tmpNote = (NSString*)ABRecordCopyValue(tmpPerson, kABPersonNoteProperty);
NSLog(@"Note:%@", tmpNote);
[tmpNote release];
//获取的联系人单一属性: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);
[tmpPhoneIndex release];
}
CFRelease(tmpPhones);
}
//释放内存
[tmpPeoples release];
CFRelease(tmpAddressBook);
}