31

My iOS application checks contacts from time to time and imports new to its own database.

I checks that contact already exists by identifier field, that usually filled by UUID:

CNContactStore *store = [CNContactStore new];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError *error) {
if (granted) {
    NSArray *keys = @[CNContactNamePrefixKey,
        CNContactGivenNameKey,
        CNContactMiddleNameKey,
        CNContactFamilyNameKey,
        CNContactInstantMessageAddressesKey];
        NSString *containerId = store.defaultContainerIdentifier;
        NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
        NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&err];            
        for (CNContact *contact in cnContacts) {
            ...
            NSString *contactId = [contact identifier];
            [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"uuid == %@", contactId]];

    ...

}

Sometimes identifier excepts UUID contains :ABPerson string (eg 9326A125-3C0A-494F-9E50-BBFCF1140EF0:ABPerson), and such contact appears just one time. Next time appears same contact, but with another UUID and without :ABPerson.

So, my contacts importer considers that they are 2 different contacts and saves them 2 times.

What is the :ABPerson string in CNContact identifier?
I know about AddressBook framework with ABPerson class, but I'm using Contacts framework for work with device contacts, why :ABPerson appears here?
Can I just filter or check this string in the identifier for preventing contacts duplicates?
Are there other strings that may be contained in CNContact identifiers?

11
  • 1
    Have you used enumeratecontactswithfetchrequest For getting Contacts ? Dec 29, 2016 at 13:18
  • No, I'm using unifiedContactsMatchingPredicate:predicate: method. I'm updated my code, so you can look this. Dec 30, 2016 at 4:31
  • 2
    If you use Google account in Address Book then after saving to AddressBook google changes contact identifier to self identifier without ":APBerson". In first moment it just removes :ABPerson, but after relaunch it changes contact identifier to another GUID. On other contacts providers it may be other rules of mutating card identifiers, so better do not use contact identifier at all.
    – poGUIst
    Apr 11, 2017 at 15:10
  • 1
    @suresh-durishetti, I manage contacts using their phone numbers that also has UUID and unlike contacts does not change them between application sessions Oct 26, 2017 at 9:16
  • 1
    Did you found an answer to this issue? Mar 22, 2018 at 14:36

1 Answer 1

0

Looks like :ABPerson is added when sharing a contact from the Contacts application. By the way, be careful because a shared contact may have a different ID even on a same device.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.