Reputation: 805
I make controller which display all contacts avaiable in phone's address book and I have to make feature of sorting these contacts. Sorting should be the same as in phone's address book. For example if in phone's address book I have set sorting by last name in my app I should have the same.
Do you know how to get information about contacts sorting which is set in iphone settings?
Upvotes: 0
Views: 76
Reputation: 346
There is this function call to sort the array of people:
CFArraySortValues(
peopleMutable,
CFRangeMake(0, CFArrayGetCount(peopleMutable)),
(CFComparatorFunction) ABPersonComparePeopleByName,
(void*) ABPersonGetSortOrdering()
);
I think that function
ABPersonGetSortOrdering()
is what you're looking for
Upvotes: 1
Reputation: 461
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy(kCFAllocatorDefault,
CFArrayGetCount(people),
people);
CFArraySortValues(peopleMutable,
CFRangeMake(0, CFArrayGetCount(peopleMutable)),
(CFComparatorFunction) ABPersonComparePeopleByName,
kABPersonSortByFirstName);
//or Use this sorting technique by the address books selected sorting technique
CFRelease(people);
for (CFIndex i = 0; i < CFArrayGetCount(peopleMutable); i++)
{
ABRecordRef record = CFArrayGetValueAtIndex(peopleMutable, i);
NSString *firstName = CFBridgingRelease(ABRecordCopyValue(record, kABPersonFirstNameProperty));
NSString *lastName = CFBridgingRelease(ABRecordCopyValue(record, kABPersonLastNameProperty));
NSLog(@"person = %@, %@", lastName, firstName);
}
CFRelease(peopleMutable);
Upvotes: 0