I use this code to get the contact list, and then I want to save the contact list in an array, just just a name, if I get how to add the whole name, then I will go ahead and other properties.
- (void)viewDidLoad {
[super viewDidLoad];
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *abContactArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSInteger totalContacts =[abContactArray count];
for(NSUInteger loop= 0 ; loop < totalContacts; loop++)
{
ABRecordRef record = (ABRecordRef)[abContactArray objectAtIndex:loop];
[myarray addObject:firstNameString];
NSLog(@"%@",[myarray objectAtIndex:1]);
if(ABRecordGetRecordType(record) == kABPersonType)
{
ABRecordID recordId = ABRecordGetRecordID(record);
recordIdString = [NSString stringWithFormat:@"%d",recordId];
firstNameString = (NSString*)ABRecordCopyValue(record,kABPersonFirstNameProperty);
lastNameString = (NSString*)ABRecordCopyValue(record,kABPersonLastNameProperty);
}
}
}
myarray is an object created NSMutableArray *myarrayin the .h class.
Any help would be greatly appreciated. Thank.
source
share