how to sort iphone contact book?
How can i sort (or retrieve sorted array of ) an iphone contact book by first name & last name programmatically ??
Any help will be well appreciated…!
- How does Square's CardCase app automatically populate the user's details from the address book?
- How do I correctly use ABAddressBookCreateWithOptions method in iOS 6?
- Search By Number and Get the image using ABAddressBook
- How to create vCard/vcf file to use in share sheet?
- NSDate return “1604” for year value?
- How Do I Obtain A User Selected Email Address From ABPeoplePicker?
3 Solutions Collect From Internet About “how to sort iphone contact book?”
ABAddressBookCopyArrayOfAllPeople() to get an array of all person records in the address book. Then follow the documentation:
To sort an array of people, use the function CFArraySortValues with the function ABPersonComparePeopleByName as the comparator and a context of the type ABPersonSortOrdering. The user’s desired sort order, as returned by ABPersonGetSortOrdering, is generally the preferred context.
The following code listing shows an example of sorting the entire Address Book database:
ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook); CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy( kCFAllocatorDefault, CFArrayGetCount(people), people ); CFArraySortValues( peopleMutable, CFRangeMake(0, CFArrayGetCount(peopleMutable)), (CFComparatorFunction) ABPersonComparePeopleByName, (void*) ABPersonGetSortOrdering() ); CFRelease(addressBook); CFRelease(people); CFRelease(peopleMutable);
How about this:–
I am using the above code (from the approved answer) to copy address book from iPhone, and also used
ABPersonComparePeopleByName for sorting the address book. But found that it
will have different sorting results for the same address book, when the
international language of the iPhone is different. Suppose it is reasonable to sort different languages based on different criteria. So in our project we have “en.lproj”..”zh-hant.lproj”…”ja.lproj”, In
NSCalendar, we also have “locale” setting. So I am thinking how to set the criteria for
ABPersonComparePeopleByName and asked Apple. A very helpful reply: “a sort order is not predictable“.
The relevant portion of Apple’s reply is below:
This is actually normal behavior. Sorting in different languages is actually an incredibly complex issue where the expectation of the user vary widely depending on language/location. Honestly, your best option is to adjust your expectations and assume that the sort order is not predictable. Any other approach is very likely to annoy and confuse many international users.
Kevin Elliott, DTS Engineer, kevin_elliott@apple,com
- iOS AVPlayer cant play 240 fps video
- Programmatically focus on next input field in mobile safari
- How to recover after i execute :git reset –hard HEAD
- How to make a UIView with optional rounded corners and border?
- Cocoa – go to foreground/background programmatically
- Passing custom data in
- IBDesignable view not rendering
- Is Swift Pass By Value or Pass By Reference
- Is this OK to understand that Activity is similar to ViewController in iOS?
- How to add new xib files
- Xcode 8.3 can't support Swift 2.3
- Setting UIDatePicker date with NSDateFormatter
- How To Disable AFNetworking Cache
- Qt: How to create a .mp4 from a collection of QOpenGLFramebufferObjects or QImages or Glunit textures
- Apple Certificate for iOS Developer and Mac Developer is expired “The certificate has an invalid issuer”