ABAddressBookGetPersonCount

ABAddressBookGetPersonCount

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

问题描述

我有一个应用程序偶尔崩溃,因为ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering()返回的数组与ABAddressBookGetPersonCount()的大小不同。代码的shell如下所示。通常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);
    }   


推荐答案

和给出不同的数组。

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返回不同的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 00:53