为什么使用CFBridgingRelease,结果数组的计数小于原来的?

时间:2015-03-08 08:10:40

标签: objective-c abaddressbook

我试图使用ABAddressBook,这是我的方法:

CFErrorRef *error = NULL;
self.addressBook = ABAddressBookCreateWithOptions(NULL, error);
self.source = ABAddressBookCopyDefaultSource(self.addressBook);
self.allPeople = [CFBridgingRelease(ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(self.addressBook, self.source, kABPersonSortByFirstName)) mutableCopy];
self.nPeople = ABAddressBookGetPersonCount(self.addressBook);

nPeople是1008,但[self.allPeople count]是2 !!!

我不明白为什么?!

1 个答案:

答案 0 :(得分:0)

结果证明默认来源是问题。其他来源中还有其他联系人,我需要全部联系。所以在ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering方法中,第二个参数应为nil以包含所有源。

CFErrorRef *error = NULL;
self.addressBook = ABAddressBookCreateWithOptions(NULL, error);
self.allPeople = [CFBridgingRelease(ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(self.addressBook, nil, kABPersonSortByFirstName)) mutableCopy];
self.nPeople = ABAddressBookGetPersonCount(self.addressBook);