What is the “:ABPerson” string in CNContact identifier?

放肆的年华 提交于 2019-12-04 15:57:32

问题


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?

来源:https://stackoverflow.com/questions/41379885/what-is-the-abperson-string-in-cncontact-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!