user7616911
user7616911

Reputation: 116

CNContact unique id between devices

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?

Upvotes: 6

Views: 651

Answers (1)

user7616911
user7616911

Reputation: 116

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.

Upvotes: 1

Related Questions