我需要从应用程序中引用 ABPerson 记录。我使用 唯一 ID 由我提供,
- (NSString *)uniqueId
并将其附加到我的应用内联系人记录中。
此外,我保存 ABP人的 vCardRepresentation 作为后备。如果应用程序不再能够使用 uniqueID 找到 ABRecord,应用程序会要求用户使用保存的 vCardRepresentation 恢复地址簿记录。一切正常。
不幸的是,一位朋友告诉我,uniqueId 并不是一成不变的:在同步期间,uniqueId 可能会突然发生变化。
据他介绍,苹果在 iOS 文档中的某个地方解释说,不存在使用 uniqueId 来不可变识别 ABPerson 的方法。在 OS X 的 Cocoa 文档中,我没有找到这样的提示。
在给定的 Mac 上,uniqueId 可能会突然改变吗?如果这是真的,那么从外部应用程序中识别 ABPerson 记录的正确方法是什么?
如果 uniqueID 不是不可变的,我当然可以使用 GUID 分配自定义属性。不幸的是,自定义字段不同步。
当然,我更喜欢使用 uniqueId。
I need to reference ABPerson records from within an application. I use the unique ID provided by
- (NSString *)uniqueId
and attach it to my in-app contact record.
Additionally, I save ABPerson's vCardRepresentation as a fallback. In case the app isn't any longer able to locate the ABRecord using the uniqueID, the app asks the user to recover the adressbook record using the saved vCardRepresentation. All works fine.
Unfortunately, a friend told me, that uniqueId isn't immutable: During a sync, uniqueId may suddenly change.
According to him, somewhere in iOS documentation, Apple explains that no way exists to immutable identify ABPersons using uniqueId. In OS X' Cocoa documentation, I failed to find such a hint.
On a given Mac, may the uniqueId change suddenly? If that's true, what's the correct way to identify ABPerson records from within an external application?
In case the uniqueID isn't immutable, I certainly may assign a custom property with a GUID. Unfortunately, custom fields do not sync.
Certainly, I'd prefer to use uniqueId.
发布评论
评论(2)
对于它的价值,来自苹果的技术文档:
kABUIDProperty
该记录的唯一 ID。 保证永远不会改变,无论记录发生多大变化。如果需要存储对记录的引用,请使用此值。类型:kABStringProperty。
适用于 Mac OS X v10.2 及更高版本。
在 ABGlobals.h 中声明。
For whats its worth, from Apple's techdoc:
kABUIDProperty
The unique ID for this record. It’s guaranteed never to change, no matter how much the record changes. If you need to store a reference to a record, use this value. Type: kABStringProperty.
Available in Mac OS X v10.2 and later.
Declared in ABGlobals.h.
看来 kABUIDProperty 方法可能不再起作用了。我在评论中发现了这篇博客文章,其中有更多讨论:
http://blog.clickablebliss.com /2011/11/07/addressbook-record-identifiers-on-mac-and-ios/。
一个恰当的例子:如果用户决定打开 iCloud 同步,则该用户地址簿中的唯一 ID 将发生变化。如果用户关闭 iCloud 同步,他们会再次更改。
附录:可能值得查看 StackOverflow 条目此处。
苹果的文档确实是这么说的(从链接中引用):
“保持对特定记录的长期引用的推荐方法是存储
除了标识符之外,还包含名字和姓氏,或者名字和姓氏的哈希值。
当您按 ID 查找记录时,请将记录的名称与您存储的名称进行比较。如果不匹配,则使用存储的名称查找记录,并存储该记录的新 ID。”
It looks like the kABUIDProperty approach might not work anymore. I came across this blog entry with more discussion in the comments at:
http://blog.clickablebliss.com/2011/11/07/addressbook-record-identifiers-on-mac-and-ios/.
A case in point: If a user decides to turn on iCloud sync, the unique ids in that user's address book will change. If the users turns off iCloud sync, they'll change again.
Addendum: it might be worthwhile looking at the StackOverflow entry here.
Apple's docs do say this (quoted from the link):
"The recommended way to keep a long-term reference to a particular record is to store the
first and last name, or a hash of the first and last name, in addition to the identifier.
When you look up a record by ID, compare the record’s name to your stored name. If they don’t match, use the stored name to find the record, and store the new ID for the record."