CNContact unique id between devices
Asked Answered
B

1

6

I'm having a bit of a problem with trying to access the same contact between multiple devices. My goal is to have a user select a contact and select a phone number and email address, which will then be stored in a database. If the user opens the app on another device, I would like to have the same contact selected.

I was hoping to use the CNContact.identifier for this case, but it appears that it is a device specific id. I could store the identifier for each device, but that would require the user matching contacts and that doesn't seam ideal.

This doesn't seam like it should be difficult but apparently I'm missing something. Thoughts?

Bessie answered 11/2, 2018 at 18:44 Comment(3)
You can't assume a user has the same contacts across devices.Orr
You are correct, some care would have to be done if it doesn't. But in cases were the contact exists in both places, it would be nice to pull in the details.Bessie
Still looking for a solution to this problem. I know Apple doesn’t supply a solution, so it’s a question of the best way to roll your own until they do. Even though users aren’t required to have the same CNContacts on each device, most of us do. Any app that accesses CNContacts shouldn’t prevent the user from having no-effort access to the same contact on all their devices where they have synced it.Pythagoras
B
1

The solution that seams to working for me is, I store the Contact identifiers, Address identifiers, Contact name, and the Address in my database. Then I take a mutli-step appoarch.

Search for Contact:
I attempt to find the contact based on the stored contact.identifiers I have already saved.

If I find 1 contact (identifier matched) => Great! I then attempt to match the found contact to my address.identifiers. Once again, if I find only 1 match, we're great! If not I then go to attempt to find an address (See below)

If I find no contacts (no identifiers matched) => I attempt to find the contact based on the Contact Name I had saved previously. If I do find a match, I then go to attempt to find the matching address (see below).

Search for Address:
Since at this point, I have a CNContact record that I believe matches, I look at each of their postalAddresses and compare it against the Street/city/state/zipcode/country that I have stored in my database.

If we find that perfect match, then I update my identifiers to include the new address/contact identifiers

If we ultimately don't find a match, I give the user an option to manually select the contact/address from their device.

Bessie answered 8/10, 2020 at 12:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.