0

I'm trying to use ABAddressBook and here is my approach:

CFErrorRef *error = NULL;
self.addressBook = ABAddressBookCreateWithOptions(NULL, error);
self.source = ABAddressBookCopyDefaultSource(self.addressBook);
self.allPeople = [CFBridgingRelease(ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(self.addressBook, self.source, kABPersonSortByFirstName)) mutableCopy];
self.nPeople = ABAddressBookGetPersonCount(self.addressBook);

The nPeople is 1008, but [self.allPeople count] is 2!!!

I don't understand why?!

Arash R
  • 402
  • 6
  • 14
  • This topic answered my question. [http://stackoverflow.com/questions/7473968/abaddressbookcopyarrayofallpeople-and-abaddressbookgetpersoncount-return-differe][1] [1]: http://stackoverflow.com/questions/7473968/abaddressbookcopyarrayofallpeople-and-abaddressbookgetpersoncount-return-differe – Arash R Mar 08 '15 at 13:28

1 Answers1

0

Turns out that the default source is the problem. There are other contacts in other sources and I need to get them all. So in ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering method, the second parameter should be nil to include all of sources.

CFErrorRef *error = NULL;
self.addressBook = ABAddressBookCreateWithOptions(NULL, error);
self.allPeople = [CFBridgingRelease(ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(self.addressBook, nil, kABPersonSortByFirstName)) mutableCopy];
self.nPeople = ABAddressBookGetPersonCount(self.addressBook);
Arash R
  • 402
  • 6
  • 14