ios获取联系信息

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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。