Search code examples
iphoneiosios4

Code example for ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering?


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?


Solution

  • 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