我需要找出ABRecordRef的来源,因为下面的方法返回来自电话簿和icloud的联系人数组,因此与同一个人(fierst,姓氏)有双重联系,但具有不同的ABRecordID recordId = ABRecordGetRecordID(记录);
ABAddressBookRef addressBook;
if ([self isABAddressBookCreateWithOptionsAvailable]) {
CFErrorRef error = nil;
addressBook = ABAddressBookCreateWithOptions(NULL,&error);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
} else if (!granted) {
} else {
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for (int i = 0; i < nPeople; i++) {
// Get the next address book record.
ABRecordRef record = CFArrayGetValueAtIndex(allPeople, i);
ABRecordID recordId=ABRecordGetRecordID(record);
NSString* firstName = (__bridge_transfer NSString*)ABRecordCopyValue(record,kABPersonFirstNameProperty);
NSString* lastName = (__bridge_transfer NSString*)ABRecordCopyValue(record,kABPersonLastNameProperty);
CFTypeRef bDayProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonBirthdayProperty);
NSDate *birthday;
if (ABRecordCopyValue((ABRecordRef)record, kABPersonBirthdayProperty))
{
birthday=(__bridge NSDate*)bDayProperty;
}
}
CFRelease(addressBook);
}
});
});
} else {
// iOS 4/5
addressBook = ABAddressBookCreate();
CFRelease(addressBook);
}
答案 0 :(得分:1)
添加新集
NSMutableSet *linkedPersonsToSkip = [[NSMutableSet alloc] init];
并检查每个人
if ([linkedPersonsToSkip containsObject:(__bridge id)(record)]) {
continue;
}
NSArray *linked = (__bridge NSArray *) ABPersonCopyArrayOfAllLinkedPeople(record);
if ([linked count] > 1) {
[linkedPersonsToSkip addObjectsFromArray:linked];
}