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