1

当视图控制器在 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?

4

2 回答 2

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);
    } 
于 2014-05-20T14:33:36.900 回答
0

Try This :

 - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
          shouldContinueAfterSelectingPerson:(ABRecordRef)person {

        ABMultiValueRef phoneNumberProperty = ABRecordCopyValue(person, kABPersonPhoneProperty);
        phoneNumbers = (__bridge NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty);

        NSLog(@"%@",phoneNumbers);
        CFRelease(phoneNumberProperty);
        return NO;

    }
于 2014-05-20T14:41:52.397 回答