Reputation: 401
i used below code for getting contacts in to our application.
this code is working fine in simulator in device allPeople getting Zero
any thing i forgot that one pls help me
if(addressBookCollection==nil) {
addressBookCollection = ABAddressBookCreate();
}
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBookCollection);
CFArrayRef allPeople= ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering (addressBookCollection,source,1);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBookCollection);
NSMutableArray* tempContactArray = [[NSMutableArray alloc] initWithCapacity:nPeople];
for(int i=0 ; i < nPeople; i++)
{
......
}
Upvotes: 0
Views: 1612
Reputation: 1693
#import<AddressBook/AddressBook.h>
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef all = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex n = ABAddressBookGetPersonCount(addressBook);
for( int i = 0 ; i < n ; i++ )
{
ABRecordRef ref = CFArrayGetValueAtIndex(all, i);
ABMultiValueRef contactnumber = ABRecordCopyValue(ref, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(contactnumber); j++)
{
CFStringRef contactnumberRef = ABMultiValueCopyValueAtIndex(contactnumber, j);
NSString *contactnumberstr = (NSString *)contactnumberRef;
CFRelease(contactnumberRef); [self.contactnumberArray contactnumber];
[contactnumber release];
}
}
you will get the contacts in array of "self.contactnumberArray".
Enjoy!
Upvotes: 2