0

I am working on contact manipulation for one app. My requirement is to maintain same ordering as native phoneBook. If there is some change in native, with one fetch by some field with some order specification I should directly get to know the location of existence or location to insert.

Applied ABPersonComparePeopleByName ordering on native phoneBook. Found that, first sorts on first name, then last name and finally phone number. if there is no first name in contacts, contacts with first name would be listed first in the order.

ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy(
                                                               kCFAllocatorDefault,
                                                               CFArrayGetCount(people),
                                                               people
                                                               );

CFArraySortValues(
                      peopleMutable,
                      CFRangeMake(0, CFArrayGetCount(peopleMutable)),
                      (CFComparatorFunction) ABPersonComparePeopleByName,
                      (void*) ABPersonGetSortOrdering()
                      );

On local phoneBook, giving

NSFetchRequest* contactReq = [[NSFetchRequest alloc] init];
[contactReq setSortDescriptors:[NSArray arrayWithObjects:[NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES selector:@selector(caseInsensitiveCompare:)],[NSSortDescriptor sortDescriptorWithKey:@"lastName" ascending:YES selector:@selector(caseInsensitiveCompare:)],[NSSortDescriptor sortDescriptorWithKey:@"phoneNumber" ascending:YES selector:@selector(caseInsensitiveCompare:)], nil]];

Problem is that, the first contact that I got on local phoneBook has no first name nor last name. Where as, they are the last entries on native phone book.

So, I am request for which sorting should I specify to get the phoneBook ordering.

Thanks, Venky

Venkatarao N
  • 245
  • 3
  • 14
  • I will close or answer the question as its not possible to decide the sorting algorithm of iOS as its closed source. Its a lot different. – Venkatarao N May 10 '13 at 12:22

1 Answers1

0

I could delete it, but this answer might address the difficulty and what happens in sorting of contacts in iOS.

  1. Programmer is provided with first name and last name as options that he/she can specify (order of preference as well).
  2. Internally it used phone number if first name and last name are not available.
  3. It has preference levels for characters I guess, i.e. contacts with name prefixed with '#' or '$' come at the bottom.
  4. Its really difficult to figure out the ordering if prefix of name is '(', ')', '"', '*' etc.
  5. I think time of creation of contact is also considered, i.e. I added a contact with '(' prefix which is placed next to ')', later I added one with ')' which is placed after previously added '('. Priority could be grouped, not sure, but its little complex and close sourced.
Venkatarao N
  • 245
  • 3
  • 14