Does anyone have a code example of how to properly set up the parameters and use the ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering() API to get sorted subsets of the iPhone Contact list?
Asked
Active
Viewed 3,987 times
2 Answers
28
The following should work:
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
-
4Note: The preferred sort order is ABPersonGetSortOrdering() - this will fill in the sort order by user preference. – n13 Feb 01 '12 at 15:57
-
1And thanks, this is awesome. It's much faster than getting all contacts and sorting them in code like I've seen in many other examples. – n13 Feb 01 '12 at 17:26
-
1Has anyone been able to do this in Swift? I can't seem to get it to work. – netwire Dec 19 '14 at 18:08
0
This worked for me:
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error);
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
NSArray *allPeople = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByFirstName);

j.f.
- 3,908
- 2
- 29
- 42

Nirav Ghori
- 69
- 5