gpt4 book ai didi

iphone - 如何有效地搜索 iOS 通讯录

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:50:42 30 4
gpt4 key购买 nike

我的应用程序能够在应用程序的不同实例之间共享其内容,即有一个按钮可以让我将文档附加到电子邮件并将其发送给应用程序的另一个用户。当他们收到此文件时,它会在他们的应用程序实例中打开。这一切正常。

但是,在导入这个数据文件的过程中,我需要应用程序将地址簿记录添加到地址簿中,除非电子邮件地址已经在地址簿中,否则它必须只返回 ABRecordRef。

我需要决定哪种方法更有效:

A - 遍历整个地址簿,创建一个用户定义的对象数组,其中包含名称和电子邮件地址(这是我所需要的)和 ABRecordRef。然后,当应用程序读取附件文件 XML 时,它必须每次都检查这个 NSArray。

B - 每当我在附件 XML 中遇到联系人时访问地址簿并根据电子邮件地址搜索它,例如ABAddressBookCopyArrayOfAllPeople

还有其他想法吗?

最佳答案

注意:这适用于通过电子邮件地址搜索。如果您按名称搜索,这不适用。

对于任意大小的地址簿,查找地址数量固定,查找地址簿的速度会更快。这是因为将所有地址放入散列中的初始成本保证至少需要线性 (O(n)) 时间相对于账簿中的地址数量,而(假设地址这本书至少是中等效率的)查找应该是对数(O(ln(n))或常数时间(O(x))取决于实现,因为你有要检查的固定数量的地址。

编辑:简单调查一下通讯录api,不能简单的“搜索通讯录”,必须复制一份,然后过滤。

Using Record Identifiers

Every record in the Address Book database has a unique record identifier. This identifier always refers to the same record, unless that record is deleted or the MobileMe sync data is reset. Record identifiers can be safely passed between threads. They are not guaranteed to remain the same across devices.

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.

To get the record identifier of a record, use the function ABRecordGetRecordID. To find a person record by identifier, use the function ABAddressBookGetPersonWithRecordID. To find a group by identifier, use the function ABAddressBookGetGroupWithRecordID. To find a person record by name, use the function ABAddressBookCopyPeopleWithName.

关于iphone - 如何有效地搜索 iOS 通讯录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9264934/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com