菜鸟教程小白 发表于 2022-12-12 19:21:53

iphone - 如何高效搜索 iOS 通讯录


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

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

<p>我需要决定哪种方法更有效:</p>

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

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

<p>还有其他想法吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>注意:这适用于通过电子邮件地址搜索。如果您按名称搜索,则不适用。</p>
<p>对于具有固定大小的地址数量的任意大小的地址簿要查找,搜索地址簿会更快。这是因为保证将所有地址放入哈希的初始成本相对于书中的地址数量至少需要线性 (<code>O(n)</code>) 时间,而(假设地址book 至少是中等效率的)查找应该是对数(<code>O(ln(n)</code>)或恒定时间(<code>O(x)</code>),具体取决于实现,因为你有要检查的固定数量的地址。</p>
<p>编辑:
对通讯录api的简单调查表明,不能简单地“搜索通讯录”,你必须复制一份,然后过滤。</p>
<blockquote>
<p>Using Record Identifiers</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
</blockquote></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 如何高效搜索 iOS 通讯录,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/9264934/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/9264934/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 如何高效搜索 iOS 通讯录