讀取所有連絡人,讀取連絡人
//讀取所有連絡人
-(void)ReadAllPeoples
{
//取得本地通訊錄名柄
ABAddressBookRef tmpAddressBook = ABAddressBookCreate();
//取得本地所有連絡人記錄
NSArray* tmpPeoples = (NSArray*)ABAddressBookCopyArrayOfAllPeople(tmpAddressBook);
for(id tmpPersonin tmpPeoples)
{
AddressList *item = [[AddressListalloc]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 = [NSStringstringWithFormat:@"%@%@",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;
[dataArrayaddObject:item];
[tmpFirstNamerelease];
[tmpLastNamerelease];
CFRelease(tmpPhones);
}
//釋放記憶體
[tmpPeoplesrelease];
CFRelease(tmpAddressBook);
}