ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering的代码示例?

时间:2011-01-09 19:27:02

标签: iphone ios ios4

有没有人有一个代码示例,说明如何正确设置参数并使用ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering()API来获取iPhone联系人列表的已排序子集?

2 个答案:

答案 0 :(得分:28)

以下内容应该有效:

ABAddressBookRef aB = ABAddressBookCreate();
ABRecordRef source = ABAddressBookCopyDefaultSource(aB); // or get the source with ABPersonCopySource(somePersonsABRecordRef);
NSArray *arr = (NSArray *)ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(aB, source, kABPersonSortByLastName);
// you can also use kABPersonSortByFirstName instead of kABPersonSortByLastName

答案 1 :(得分:0)

这对我有用:

ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error);
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
NSArray *allPeople = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByFirstName);