Contacts Framework Identifiers
Apple announced a new Contacts Framework at WWDC (2015). There’s a great session on the framework as well reference documentation. It will be available in iOS 9 and OS X El Capitan in the Fall and promises to make it much easier to work with the system contacts datastore, which, to date has relied on a rather archaic C-style Address Book API which is painful to use.
I’ve experimented with the the Contacts Framework a bit. One thing that caught my attention was that the documentation specifically calls out that identifier properties for contact, group and other objects vended by the framework can be persisted between app launches.
This intrigued me, because it would be neat if, for example, my app Drafts could create actions that linked directly to a contact rather than having hard coded email/phone number information.
Universal identifiers seemed out of line with Apple’s usual attention to privacy, so I thought I’d play around with how the identifiers work.
It appears the identifiers given are unique to the device, but not the app, and are changed if a contact is ever removed and restored to the device via any sort of sync process.
Assuming Device A and Device B, both synching contacts (via iCloud or other service), the follow statements appear to all be true:
- App A will get the same identifier for the same contact as App B if both are running on Device A.
- App A running on the Device A and App A running on Device B will get different identifiers for the same contact.
- If a Contact is not removed from a device, it’s identifier will remain the same for all apps requesting it, even if the apps are deleted and reinstalled.
- If a Contact A is removed and re-synced to the device–because the sync account was removed and readded, etc.–it will get a new identifier.
This is the result of basic testing with iOS 9 beta 2, obviously some aspects of this could change before final versions ship.
Long story short, it would not be practical for Drafts to have an action that linked directly to a contact, because it would not be possible to sync that action across devices and still have it point to the same contact.