当视图控制器在iOS 7中显示合并的联系人时,我在处理ABPersonViewController上的操作时遇到问题。
在下面的示例中,ABPersonViewController为显示的联系人显示了7行,但是当我获取属性的ABMultiValueRef时,它返回8行,其中第一行被隐藏,因为它在此组合联系人中是重复的。
当为索引读取值时,它是隐藏的值,因此读取的所有值都是ABPersonViewController中显示的值之一
-(BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
if (property == kABPersonPhoneProperty){
ABMultiValueRef phone = ABRecordCopyValue(person, property);
CFIndex theindex = ABMultiValueGetIndexForIdentifier(phone, identifier);
NSString *selectedValue = (NSString *)ABMultiValueCopyValueAtIndex(phone, the index);
// DO SOMETHING WITH THE SELECTED VALUE
CFSafeRelease(phone);
CFSafeRelease(selectedValue);
}
return NO;
}
有没有办法在组合联系人时获取索引的正确值,或者有没有办法获得实际显示在ABPersonViewController中的属性的MultiValueRef?
答案 0 :(得分:0)
ABPropertyType pt = ABPersonGetTypeOfProperty(property);
NSString *phoneNumber;
if ((pt & kABMultiValueMask) == kABMultiValueMask) {
ABMultiValueRef phoneProperty = ABRecordCopyValue(person,property);
CFIndex idx = ABMultiValueGetIndexForIdentifier(phoneProperty, identifier);
phoneNumber = (__bridge NSString *)ABMultiValueCopyValueAtIndex(phoneProperty,idx);
CFRelease(phoneProperty);
}
答案 1 :(得分:0)
试试这个:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
ABMultiValueRef phoneNumberProperty = ABRecordCopyValue(person, kABPersonPhoneProperty);
phoneNumbers = (__bridge NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty);
NSLog(@"%@",phoneNumbers);
CFRelease(phoneNumberProperty);
return NO;
}