How to use ABAddressBookRef in iOS app?

Total Post:10

 967  View(s)
Rate this:

I am using ABAddressBookRef as a reference for my device contacts.
this is my code that I am using in our app:

ABAddressBookRef phoneContacts = ABAddressBookCreate();
NSMutableArray *allContacts = [[[(NSArray*)ABAddressBookCopyArrayOfAllPeople (phoneContacts) autorelease] mutableCopy]autorelease];
[allContacts sortUsingFunction:(int (*)(id,id,void*)) ABPersonComparePeopleByName context:(void*)ABPersonGetSortOrdering()];
NSLog(@"No of Contacts:%i",[allContacts count]);
for(int i=0; i<[allContacts count]; i++)
  ABRecordRef person = [allContacts objectAtIndex:i];
  //get phone no fill phone no into  array
  ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
  if(multi!=NULL && ABMultiValueGetCount(multi)>0)
  } else {

But this returns 0 from [people count], while I have 10 contacts on my device.
I am not understanding what I am missing here.
Please help me.


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.