开发者

iPhone ABContact address book sorting.

开发者 https://www.devze.com 2023-02-15 07:51 出处:网络
How can I sort my address book by first n开发者_Go百科ame. I\'m using the ABContact class.First you need to get an array of all the contacts with the method :

How can I sort my address book by first n开发者_Go百科ame. I'm using the ABContact class.


First you need to get an array of all the contacts with the method :

CFArrayRef ABAddressBookCopyArrayOfAllPeople (
   ABAddressBookRef addressBook
);

Then you can create a mutable version of the array using :

CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy(
                                          kCFAllocatorDefault,
                                          CFArrayGetCount(people),
                                          people
                                  );

And you can sort this array with :

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

You have a fully documented sample in the Address Book Programming guide

Hope this helps, Vincent

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号