Using the built-in Address Book framework for iPhone, how can I save a specific list of contacts to an array in NSUserDefaults? I need to save a list of recipients for later.
使用iPhone内置的地址簿框架,如何在NSUserDefaults中将联系人列表保存到数组中呢?我需要为以后保存一个收件人列表。
I want to make sure I do not run into problems if the user edits the contacts after my application is closed. Is there some sort of unique ID that each contact has, that I can save and look-up later?
我想确保在我的应用程序关闭后,如果用户编辑联系人,我不会遇到问题。是否每个联系人都有某种唯一的ID,我可以保存并在以后查找?
3 个解决方案
#1
2
ABRecordID
's most certainly do change (having learned this the hard way - as a result of multiple machine contact sync)
ABRecordID最肯定的是做了改变(由于多台机器的接触同步,这是一种艰难的学习方式)
Matt Gemmell has a nice writeup at iphone-dev-tips-for-synced-contacts
Matt Gemmell在iphone-dev-tips-for-synced-contacts中有一个不错的记录。
I don't store the composite name, but rather the ABRecordId, first name, last name, an email address and a phone number (the last two of which are used directly by my app).
我不存储合成名称,而是存储ABRecordId、名、姓、电子邮件地址和电话号码(最后两个是我的应用直接使用的)。
If I don't get a hit on
如果我没有被击中
ABRecordRef aRef = ABAddressBookGetPersonWithRecordID(addressBook, aRecordId);
I use a bunch of code to find potential matches on last name, first name and then refine it by phone numbers.
我使用一堆代码来查找姓、名的潜在匹配项,然后通过电话号码对其进行细化。
As a final aside, I am associating a generated UUID for the contact so that all of this (potentially) fuzzy resolution is abstracted out of the data I'm associating with a contact.
最后,我把一个生成的UUID与联系人联系起来,这样所有的(潜在的)模糊的分辨率就会从我联系的数据中提取出来。
#2
2
Be careful with this, I believe there was an issue (at least in pre OS3.0) where this ABRecordID could change when the user synced their device. This can obviously cause problems if you are relying on using that ID again. I don't know if this is still happening in OS3.0 or not.
请注意,我认为有一个问题(至少在pre OS3.0中),当用户同步设备时,这个ABRecordID可能会改变。如果您再次依赖于使用该ID,这显然会导致问题。我不知道这在OS3.0中是否仍然存在。
http://discussions.apple.com/thread.jspa?threadID=1771736
http://discussions.apple.com/thread.jspa?threadID=1771736
Just something to watch out for.
只是需要注意的事情。
#3
0
The ABRecordRef has an ABRecordID property that you should be able to use to uniquely identify it for later access.
ABRecordRef有一个ABRecordID属性,您应该可以使用它来唯一地标识它以便以后访问。
#1
2
ABRecordID
's most certainly do change (having learned this the hard way - as a result of multiple machine contact sync)
ABRecordID最肯定的是做了改变(由于多台机器的接触同步,这是一种艰难的学习方式)
Matt Gemmell has a nice writeup at iphone-dev-tips-for-synced-contacts
Matt Gemmell在iphone-dev-tips-for-synced-contacts中有一个不错的记录。
I don't store the composite name, but rather the ABRecordId, first name, last name, an email address and a phone number (the last two of which are used directly by my app).
我不存储合成名称,而是存储ABRecordId、名、姓、电子邮件地址和电话号码(最后两个是我的应用直接使用的)。
If I don't get a hit on
如果我没有被击中
ABRecordRef aRef = ABAddressBookGetPersonWithRecordID(addressBook, aRecordId);
I use a bunch of code to find potential matches on last name, first name and then refine it by phone numbers.
我使用一堆代码来查找姓、名的潜在匹配项,然后通过电话号码对其进行细化。
As a final aside, I am associating a generated UUID for the contact so that all of this (potentially) fuzzy resolution is abstracted out of the data I'm associating with a contact.
最后,我把一个生成的UUID与联系人联系起来,这样所有的(潜在的)模糊的分辨率就会从我联系的数据中提取出来。
#2
2
Be careful with this, I believe there was an issue (at least in pre OS3.0) where this ABRecordID could change when the user synced their device. This can obviously cause problems if you are relying on using that ID again. I don't know if this is still happening in OS3.0 or not.
请注意,我认为有一个问题(至少在pre OS3.0中),当用户同步设备时,这个ABRecordID可能会改变。如果您再次依赖于使用该ID,这显然会导致问题。我不知道这在OS3.0中是否仍然存在。
http://discussions.apple.com/thread.jspa?threadID=1771736
http://discussions.apple.com/thread.jspa?threadID=1771736
Just something to watch out for.
只是需要注意的事情。
#3
0
The ABRecordRef has an ABRecordID property that you should be able to use to uniquely identify it for later access.
ABRecordRef有一个ABRecordID属性,您应该可以使用它来唯一地标识它以便以后访问。