0

When I scroll My Contacts App to the bottom, where it shows the number of contacts, It says 2568 contacts.

But in my app when I try to fetch the number of contacts from AddressBook, by ABAddressBookGetPersonCount, I get 2582 contacts.

Has Anyone noticed this? Why is this difference there? Does the AddressBook framework give me wrong information??

EDIT

 CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
 CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
 NSLog(@"num people to send: %ld", nPeople);
 NSLog(@"num people in array: %ld", CFArrayGetCount(allPeople));

These two logs, give me the same number, however this number is different from that written at the bottom of the contacts app in iphone.

Nikita P
  • 4,226
  • 5
  • 31
  • 55
  • Is there is any contact which contains two or more mobile fields. – JiteshW Jun 03 '13 at 11:12
  • @Jitesh yes there are. But when i print the list, the name does not show two times. – Nikita P Jun 03 '13 at 13:27
  • Are you using sets to store the contact name OR you are allowing only unique entreis in arry. If you are using sets than it will only contain uniques entries. I think u should get names more than one if you have multiple mobile fields in you contact. Can you post the code . – JiteshW Jun 04 '13 at 05:40

2 Answers2

0

The contacts app pulls in its contacts from various groups. You can change the number of people in your list by going to the groups select page (top left in IOS 7) and selecting or deselecting your contacts.

If your list is pulling in all the contacts 'available' to you, the difference is due to contacts coming from a source not used in the Contacts App. You may have noticed that you can start to type in an email and it will auto fill the email even though you have no contact for that person. That information is stored inside the AddressBook database, but is not pulled into the Contact App. When you use the ABAddressBookCopyArrayOfAllPeople, it also pulls in these 'contacts'. You can verify this by putting all the contact's in a tableview and printing out the name, first email, first phone number, for each of the contacts. You will probably find a few contacts which only contain an email address (or possibly phone number).

An example of how to print off all the contacts can be found here.

Jbryson
  • 2,875
  • 1
  • 31
  • 53
0

Use this code

ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
CFArrayRef allPeople = (ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByFirstName));
//CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
CFIndex nPeople = CFArrayGetCount(allPeople); // bugfix who synced contacts with facebook
Ayaz
  • 1,398
  • 15
  • 29