我制作控制器,显示电话通讯录中可用的所有联系人,我必须具有对这些联系人进行排序的功能。排序应与手机通讯录中的排序相同。 例如,如果在手机的地址簿中我已经在我的应用程序中设置了按姓氏排序,我应该有相同的。
您知道如何获取有关iphone设置中设置的联系人排序的信息吗?
答案 0 :(得分:1)
这个函数调用可以对人数组进行排序:
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);