I have an app that uses address book. I am trying to display sorted list of names from address book using
sortedArray = [arr_contactList sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
and then when user selects one of the contacts, its phone number is displayed.
I am able to sort iPhone address book phone numbers.
I use following to sort phone numbers:
ABRecordRef source = ABAddressBookCopyDefaultSource(ab);
NSArray *thePeople = (NSArray*)ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(ab, source, kABPersonSortByFirstName);
NSString *name;
for (id person in thePeople)
{
name = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
{
NSString* num = (NSString*)ABMultiValueCopyValueAtIndex(phones, j);
CFStringRef locLabel1 = ABMultiValueCopyLabelAtIndex(phones, j);
NSString *phoneLabel1 =(NSString*) ABAddressBookCopyLocalizedLabel(locLabel1);
[tempPhoneArray addObject:num];
}
}
But my actual problem is, my names array has contacts that begin with special characters on top of the list, and when I select phone nos, the contact list sorted starts with alphabet A. So I am getting wrong phone numbers.
How do I match both the sorts - the name sort and numbers sort?