0

I need someway to uniquely identify a contact in contact store even if the contact is changed.

Is there a way to put code in iOS that is always watching in the background for the contact store to change? That way I can track a contact that I identify with a UUID value and make sure I can always match that specific contact with its UUID value even if the contact changes. If I put it in my app, then the user can close the app, and the app won't receive notifications when the contact store changes? Is there an app extension I can use that would allow me to do this, whether that is the intent of the extension or not?

Perhaps I can use key-value observing. Is it possible to observe the iOS Contacts app or the contacts store of a device using key-value observing? How would I find out? I can't find information on it when I do a search on Google.

I found information about the ABAddressBookRegisterExternalChangeCallback(::_:) function of the Address Book Framework, but that function has been deprecated, and only works with iOS 2.0–9.0. I don't see a function in the Contacts Framework that does what that function does.

Content Added Thursday, March 3, 2022, 12:03 AM:

I need the unique identifier to be saved in a record in a private iCloud database. The objective is to be able to query the database for the record associated with that contact. That would probably mean that the identifier would have to be unique across all iOS devices in existence.Is that so?

daniel
  • 1,446
  • 3
  • 29
  • 65
  • 1
    `CNContact.identifier` is exactly what you're describing in your subject. "A value that uniquely identifies a contact on the device." Your question seems to be about being notified when a contact is changed when your app is not running. That's not possible, but is unrelated to identifying a contact. Which are you trying to do? There are extremely few cases where your app will be launched just because something changes on the device (BLE connections are one of the rare exceptions). But you can definitely check the next time you app is launched. – Rob Napier Mar 02 '22 at 20:21
  • 1
    When in the foreground, observe the `CNContactStoreDidChange` notification and check any contacts you're observing. It's not clear if you need anything more than that. – Rob Napier Mar 02 '22 at 20:21
  • @RobNapier Ok. So identifier properties of CNContact objects stored in contact store don't change then? – daniel Mar 03 '22 at 06:10
  • @RobNapier I added content to the question and dated it Thursday, March 3, 2022, 12:03 AM, to explain why I need to uniquely identify the contact object in the first place. – daniel Mar 03 '22 at 06:11
  • 1
    Check the docs for `CNContact.identifier`: "An identifier can be persisted between the app launches. Note that this identifier only uniquely identifies the contact on the current device." – Rob Napier Mar 03 '22 at 13:54
  • 1
    As for whether there is a cross-device stable identifier, see https://stackoverflow.com/questions/37348999/is-there-a-cross-device-cncontact-identifier I'm not aware of any changes to that. – Rob Napier Mar 03 '22 at 13:54

0 Answers0