读取通讯录信息
-(void)ReadAllPeoples
{
//取得本地通信录名柄
ABAddressBookRef tmpAddressBook = nil;
if ([[UIDevicecurrentDevice].systemVersionfloatValue]>=6.0) {
tmpAddressBook=ABAddressBookCreateWithOptions(NULL, NULL);
dispatch_semaphore_t sema=dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(tmpAddressBook, ^(bool greanted, CFErrorRef error){
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
}
else
{
tmpAddressBook =ABAddressBookCreate();
}
//取得本地所有联系人记录
if (tmpAddressBook==nil) {
return ;
};
NSArray* tmpPeoples = (__bridgeNSArray*)ABAddressBookCopyArrayOfAllPeople(tmpAddressBook);
for(id tmpPerson in tmpPeoples)
{
//获取的联系人单一属性:First name
NSString* tmpFirstName = (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonFirstNameProperty);
NSLog(@"First name:%@", tmpFirstName);
//获取的联系人单一属性:Last name
NSString* tmpLastName = (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonLastNameProperty);
NSLog(@"Last name:%@", tmpLastName);
//获取的联系人单一属性:Nickname
NSString* tmpNickname = (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonNicknameProperty);
NSLog(@"Nickname:%@", tmpNickname);
//获取的联系人单一属性:Company name
NSString* tmpCompanyname = (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonOrganizationProperty);
NSLog(@"Company name:%@", tmpCompanyname);
//获取的联系人单一属性:Job Title
NSString* tmpJobTitle= (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonJobTitleProperty);
NSLog(@"Job Title:%@", tmpJobTitle);
//获取的联系人单一属性:Department name
NSString* tmpDepartmentName = (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonDepartmentProperty);
NSLog(@"Department name:%@", tmpDepartmentName);
//获取的联系人单一属性:Email(s)
ABMultiValueRef tmpEmails = ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonEmailProperty);
for(NSInteger j = 0; ABMultiValueGetCount(tmpEmails); j++)
{
NSString* tmpEmailIndex = (__bridge NSString*)ABMultiValueCopyValueAtIndex(tmpEmails, j);
NSLog(@"Emails%d:%@", j, tmpEmailIndex);
}
CFRelease(tmpEmails);
//获取的联系人单一属性:Birthday
NSDate* tmpBirthday = (__bridgeNSDate*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonBirthdayProperty);
NSLog(@"Birthday:%@", tmpBirthday);
//获取的联系人单一属性:Note
NSString* tmpNote = (__bridgeNSString*)ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonNoteProperty);
NSLog(@"Note:%@", tmpNote);
//获取的联系人单一属性:Generic phone number
ABMultiValueRef tmpPhones = ABRecordCopyValue((__bridgeABRecordRef)(tmpPerson), kABPersonPhoneProperty);
for(NSInteger j = 0; j < ABMultiValueGetCount(tmpPhones); j++)
{
NSString* tmpPhoneIndex = (__bridge NSString*)ABMultiValueCopyValueAtIndex(tmpPhones, j);
NSLog(@"tmpPhoneIndex%d:%@", j, tmpPhoneIndex);
}
CFRelease(tmpPhones);
}
CFRelease(tmpAddressBook);
}