Home > DeveloperSection > Forums > How to use ABAddressBookRef in iOS app?
monica frank
monica frank

Total Post:10

Posted on    December-01-2015 10:28 PM

 iPhone iPhone  Ios  Objective C 

 0 Reply(s)
 538  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.

Don't want to miss updates? Please click the below button!

Follow MindStick