Retrieving and displaying AddressBook in Table view.
Posted
by Prash.......
on Stack Overflow
See other posts from Stack Overflow
or by Prash.......
Published on 2010-06-12T13:15:00Z
Indexed on
2010/06/12
13:22 UTC
Read the original article
Hit count: 319
iphone
hi,
I am developing an application in which i have to retrieve all Addressbook (Name & Phone No) records and Display it in table view,
this is my Snippet for retrieving records from addressbook.
NSArray *tableGroups;
ABAddressBookRef m_addressbook = ABAddressBookCreate();
if (!m_addressbook) {
NSLog(@"opening address book");
}
CFArrayRef allPeople= ABAddressBookCopyArrayOfAllPeople(m_addressbook);
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);
NSMutableArray *selectableRows = [NSMutableArray array];
for (int i=0;i < nPeople;i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
ABMutableMultiValueRef phoneMulti = ABRecordCopyValue(ref, kABPersonPhoneProperty);
CFStringRef phoneNumber= ABMultiValueCopyValueAtIndex(phoneMulti, i);
NSString *contactFirstLast = [NSString stringWithFormat:@"%@,%@", ABRecordCopyValue(ref, kABPersonFirstNameProperty),phoneNumber];
printf("%s\n", [contactFirstLast UTF8String]);
[selectableRows addObject:[NSString stringWithFormat:contactFirstLast, i]];
CFRelease(phoneNumber);
CFRelease(ref);
CFRelease(contactFirstLast);
CFRelease(phoneMulti);
}
tableGroups = [[NSArray alloc] initWithObjects:selectableRows, nil];
I am getting exception as "CFRetain" and apps get crash.
Please suggest me proper solution for that..
© Stack Overflow or respective owner