Basically I have a Conversation object that has a contact: CNContact? property, and what I want to do is update the contact info when updated. What I am doing now is subscribe to Notification.Name.CNContactStoreDidChange notification, get the CNNotificationSaveIdentifiersKey identifiers array from the userInfo and compare if any of the ids is equal to the conversation's contact id.

The problem is that none of the ids match, they even have different format

Conversation contact identifier: 68269F08-6B22-4B69-BEA1-431805F328D1:ABPerson

Notification Contact Identifier: 6F959AA0-5EEF-4C38-B9C7-BEA57F270927

The questions is: Is this the correct way to identify which contact was updated?

This is the code:

//somewhere in the conversation object
NotificationCenter.default.addObserver(forName: Notification.Name.CNContactStoreDidChange, object: nil, queue: .main) { (notification) in            
            guard
                let conversationContact = self.contact,
                let userInfo = notification.userInfo,
                let indentifiers = userInfo["CNNotificationSaveIdentifiersKey"] as? [String],
                let notificationIdentifier = indentifiers.first else {
                return
            }

            print(conversationContact.formattedName ?? "nil name")
            print("conversationContact.identifier \(conversationContact.identifier)")

            print("notificationIdentifier \(notificationIdentifier)")

            if conversationContact.identifier == notificationIdentifier {
                self.contact = nil
            }
        }
    ```
0

There are 0 best solutions below