1

I am having an issue handling an action on an ABPersonViewController when the view controller is displaying a merged contact in iOS 7.

In the below example the ABPersonViewController showed 7 rows for the contact being displayed but when I fetch the ABMultiValueRef for the property it returns 8 rows where the first row was hidden because it was a duplicate on this combined contact.

When the value is read for the index it is the one that is hidden so all values read are one off the one that was displayed in the 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;
}

Is there a way to get the correct value for the index when the contacts are combined, or is there a way to get the MultiValueRef for the property that was actually displayed in the ABPersonViewController?

2 Answers2

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);
    } 
Syed Absar
  • 2,274
  • 1
  • 26
  • 45
  • 1
    have you tried your solution with linked contacts? e.g. you have Contact A and Contact B. B is linked to A - i.e. You will see B's numbers listed inside A's person view. When you try to click B's number, the index is wrong... – xialin Jun 11 '14 at 12:36
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;

    }
Gopal Raju
  • 246
  • 3
  • 12