How to get all contacts from ABAddressBook without duplicates

To get all contacts I use a method ABAddressBookCopyArrayOfAllPeople

, but this method returns all contacts with duplicates: in the Contacts app I saw that almost all of my contacts have an associated card (this shows me that I have two identical contacts one from iCloud and another from my iPad). As I can see for this reason the method ABAddressBookCopyArrayOfAllPeople

returns duplicate contacts.
How to get all contacts from ABAddressBook without duplicate?

+3


source to share


3 answers


Perhaps ABContactHelper can help ?!



+2


source


From memory, I think this only returns one entry per user:

    ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
    addressBookArray = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByLastName);

      



I have used it and it works. Though you'll have to jump over the linked contacts to get the details of the user.

Don't forget to download the CFRelease source and addressBook when you're done.

+1


source


I had the same problem and found no other solution, then manually: bi-directional two-way duplicate removal process:

Two cascading loops (ordo n ^ 2) that oppose the record ID of each pin pair that was returned ABAddressBookCopyArrayOfAllPeople

. Then I add only the contact with the lower contact ID to the final list. This is not a very pretty solution, but it works for me.

0


source







All Articles