title: Dealing with duplicate contacts due to linked cards in iOS' Address Book API
body: <p>Some beta-users of <a href="http://twelvetwenty.nl/gettogether" rel="noreferrer">my upcoming app</a> are reporting that the list of contacts contain a lot of duplicate records. I'm using the result from <a href="https://developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html#//apple_ref/c/func/ABAddressBookCopyArrayOfAllPeople" rel="noreferrer"><code>ABAddressBookCopyArrayOfAllPeople</code></a> as the data source for my customized table view of contacts, and it baffles me that the results are different from the iPhone's 'Contacts' app.</p>
  
  <p>When looking more closely at the Contacts app, it seems that the duplicates originate from entries with "Linked Cards". The screenshots below have been obfuscated a bit, but as you see in my app on the far right, "Celine" shows up twice, while in the Contacts app on the left there's only one "Celine". If you click the row of that single contact, you get a "Unified Info" card with two "Linked Cards" <em>(as shown in the center, I didn't use Celine's contact details because they didn't fit on one screenshot)</em>:</p>
  
  <p><img src="https://i.stack.imgur.com/ecvJc.png" alt="Screenshot"></p>
  
  <p>The issues around "Linked Cards" have <a href="https://discussions.apple.com/message/17320564#17320564" rel="noreferrer">quite</a> a <a href="https://discussions.apple.com/thread/2475796?start=0&amp;tstart=0" rel="noreferrer">few topics</a> on <a href="https://discussions.apple.com/message/13089845#13089845" rel="noreferrer">Apple's forums</a> for end users, but apart from the fact that many point to a <a href="http://support.apple.com/kb/HT3677" rel="noreferrer">404 support page</a>, I can't realistically go around fixing all of my app's users' address books. I would much rather like to deal with it elegantly and without bothering the user. To make matters worse, it seems I'm not the only one with this issue, since <a href="http://www.quora.com/WhatsApp-Messenger/How-can-I-delete-duplicate-contacts-in-WhatsApp" rel="noreferrer">WhatsApp is showing the same list containing duplicate contacts</a>.</p>
  
  <p><em>Just to be clear about the origins of the duplicate contacts, I'm not storing, caching or otherwise trying to be smart about the array <code>ABAddressBookCopyArrayOfAllPeople</code> returns. So the duplicate records come directly from the API call.</em></p>
  
  <p>Does anyone know how to deal with or detect these linked cards, preventing duplicate records from showing up? Apple's Contacts app does it, how can the rest of us do so too?</p>
  
  <p><strong>UPDATE: I wrote a library and put it on Cocoapods to solve the issue at hand. See my answer below</strong></p>