HOW TO USE ABADDRESSBOOKREF IN IOS APP?

monica frank

Total Post:10

Points:70
Posted by  monica frank
 553  View(s)
Ratings:
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)
  {
     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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!