forum

Home / DeveloperSection / Forums / How to use ABAddressBookRef in iOS app?

How to use ABAddressBookRef in iOS app?

Anonymous User 1362 01-Dec-2015

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)
  {
     NSLog(@"Available");
  } else {
     NSLog(@"Not-Available");
  }
}

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.


Updated on 01-Dec-2015
I am a content writter !

Can you answer this question?


Answer

0 Answers

Liked By