有关在电话通讯录iOS中排序的信息

时间:2014-04-04 13:37:07

标签: ios iphone objective-c

我制作控制器,显示电话通讯录中可用的所有联系人,我必须具有对这些联系人进行排序的功能。排序应与手机通讯录中的排序相同。 例如,如果在手机的地址簿中我已经在我的应用程序中设置了按姓氏排序,我应该有相同的。

您知道如何获取有关iphone设置中设置的联系人排序的信息吗?

2 个答案:

答案 0 :(得分:1)

阅读本文: https://developer.apple.com/library/ios/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/DirectInteraction.html#//apple_ref/doc/uid/TP40007744-CH6-SW1

这个函数调用可以对人数组进行排序:

CFArraySortValues(

    peopleMutable,

    CFRangeMake(0, CFArrayGetCount(peopleMutable)),

    (CFComparatorFunction) ABPersonComparePeopleByName,

    (void*) ABPersonGetSortOrdering()

);

我认为这个功能

ABPersonGetSortOrdering()

是您正在寻找的

答案 1 :(得分:0)

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

CFArraySortValues(peopleMutable,
                  CFRangeMake(0, CFArrayGetCount(peopleMutable)),
                  (CFComparatorFunction) ABPersonComparePeopleByName,
                  kABPersonSortByFirstName);

//or Use this sorting technique by the address books selected sorting technique

CFRelease(people);


for (CFIndex i = 0; i < CFArrayGetCount(peopleMutable); i++)
{
    ABRecordRef record = CFArrayGetValueAtIndex(peopleMutable, i);
    NSString *firstName = CFBridgingRelease(ABRecordCopyValue(record, kABPersonFirstNameProperty));
    NSString *lastName = CFBridgingRelease(ABRecordCopyValue(record, kABPersonLastNameProperty));
    NSLog(@"person = %@, %@", lastName, firstName);
}

CFRelease(peopleMutable);