Address Book contacts in Core Data
Asked Answered
S

2

15

What’s considered ‘best practice’ when saving Address Book contacts in Core Data?

I’m writing an iPhone App, based on Core Data, where I need to save and recall Address Book contacts as part of the data model.

In the UI I plan to present a screen where the user can pick a contact from the current Address Book, create a new contact to store in the Address Book, or just create a ‘one-off’ contact with no saved record, local to the App only. These contacts are tracked in the context of the orders they have made, and not all contacts will require saving outside the App itself.

It feels ‘wrong’ to copy the data from the Address Book if using an existing entry, but not sure what to do if an Address Book record is edited or deleted.

I only need to track name and photo for the purposes of the App, so gut-reaction is to store the ABRecordID, and—because these can apparently change(!)—the first and last name, and only update local record if it’s updated (how to track that?).

Or can you store a ABRecordRef directly? (I imagine they aren’t persistent?)

I’ve done some searching on Google, and here, but can’t find any code samples or discussion on the integration of Core Data and Address Book in this manner; just lots of stuff on each in isolation.

Any one with some experience/gotchas on this subject point them out, or point me in the direction of some more reading?

Thanks.

Andy W

Smriti answered 23/2, 2010 at 18:21 Comment(0)
A
5

I would store the ABRecordID and then handle the situation for when they change although I have not personally seen a case where they change except when the user deletes all data and restores it from another source (moving from MobileMe to Google for example).

Ajay answered 23/2, 2010 at 19:30 Comment(1)
That does not work. The ABRecordID is not constant across devices for the same record.Faqir
S
3

See Apples online Documentation on how to handle changing ids and what to store.

Spann answered 21/3, 2011 at 10:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.