ABAddressBookCopyArrayOfAllPeople 和 ABAddressBookGetPersonCount 返回不同的大小 [英] ABAddressBookCopyArrayOfAllPeople and ABAddressBookGetPersonCount return different sizes

查看:10
本文介绍了ABAddressBookCopyArrayOfAllPeople 和 ABAddressBookGetPersonCount 返回不同的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering() 返回的数组与 ABAddressBookGetPersonCount() 的大小不同,我有一个应用程序偶尔会崩溃.代码的外壳如下所示.通常 nPeople 与数组的大小相同.然而,在一位用户的 iPhone 上(或至少,正如一位用户所报告的那样),nPeople 几乎是原来的两倍.我可以通过使用数组大小​​而不是 ABAddressBookGetPersonCount() 来阻止崩溃.但是,我不确定这是否意味着我没有访问 iPhone 中的所有联系人.

I have an app which crashes occasionally due to the array returned by ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering() having a different size to ABAddressBookGetPersonCount(). The shell of the code is shown below. Usually nPeople is the same size as the array. However, on one user's iPhone (or at least, as reported by one user), nPeople is almost twice as large. I can stop the crash by using the array size, rather than ABAddressBookGetPersonCount(). However, I am not sure if this means I am not accessing all of the Contacts in the iPhone.

  • 以前有人遇到过这个问题吗?
  • 为什么数字会不同?

我想知道这是否与存储在组中的联系人有关(我不知道有组 - 只是一个想法).另外,从用户的电子邮件地址来看,我怀疑他们使用的是 MobileMe.我想知道与 MobileMe 同步是否会创建具有不同 recordId 的副本,但不会删除现有的联系人,至少不会像 ABAddressBookGetPersonCount() 那样.

I wondered if it was something to do with the contacts being stored in Groups (I do not know that there are groups - just an idea). Also, from the user's email address, I suspect they use MobileMe. I wondered if syncing with MobileMe would create duplicates with a different recordId, but not delete the existing Contact, at least not as far as ABAddressBookGetPersonCount() goes.

我对此进行了更多研究,并对问题的原因有了一个很好的了解.因为我想要一个排序的联系人数组,所以我使用了 ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering().这需要一个地址簿来源——我使用了默认来源.我相信可能有多种来源——本地来源以及其他来源,例如 Exchange 和 MobileMe.因此,我的数组最终将只包含本地联系人,而 ABAddressBookGetPersonCount() 返回的数字将包括所有来源 - 因此我的崩溃.因此,我认为在我的应用程序中使用本地数据并使用 ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering 返回的数组大小而不是 ABAddressBookGetPersonCount 会更好.

I have looked into this some more and have a fairly good idea at the cause of the problem. As I wanted a sorted array of contacts, I used ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(). This requires an address book source - I used the default source. I believe there can be various sources - the local source plus others such as Exchange and MobileMe. Therefore, my array will end up with just the local contacts, whereas the number returned by ABAddressBookGetPersonCount() will include all sources - hence my crash. Therefore, I think it would be better to just work with the local data in my app and use the array size returned by ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering rather than ABAddressBookGetPersonCount.

CFArrayRef allPeople = InSourceWithSortOrdering(addressBook, source, kABPersonSortByLastName);  

    CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);

    for (int i = 0; i < nPeople; i++) 
    {
        ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
    }   

推荐答案

ABAddressBookGetPersonCountABAddressBookCopyArrayOfAllPeople 给出了不同的数组.

ABAddressBookGetPersonCount And ABAddressBookCopyArrayOfAllPeople gives different arrays.

ABAddressBookGetPersonCount - 返回地址簿中的人员记录数.ABAddressBookCopyArrayOfAllPeople - 返回地址簿中的所有人员记录.

ABAddressBookGetPersonCount - Returns the number of person records in an address book. ABAddressBookCopyArrayOfAllPeople - Returns all the person records in an address book.

所以有时同一个人可能有额外的记录.这就是为什么你可能会得到不同的尺寸.

So some times same person may have extra records. That's why you may getting different sizes.

这篇关于ABAddressBookCopyArrayOfAllPeople 和 ABAddressBookGetPersonCount 返回不同的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆