-1

I am trying to get the email value of an address book contact.

I need to capture which email the user click and I can figure out how to get the syntax right.

I used an example which picked the first email available, but I am now trying to switch it to the email that the user selects. I started writing //NSString* email = ABRecordCopyValue(property, );

or how to get the index value of what the user selected. If I had the index value of the email selected, I could reuse the code that I had commented out.

- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
  shouldContinueAfterSelectingPerson:(ABRecordRef)person
                            property:(ABPropertyID)property
                          identifier:(ABMultiValueIdentifier)identifier
{

    NSString* name = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);

    self.userName.text = name;

    self.myMessage.recpipientName = name;

    //NSString* email = ABRecordCopyValue(property)

    ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);

    //    if (ABMultiValueGetCount(emails) > 0) {

    //        email = (__bridge_transfer NSString*)

    //        ABMultiValueCopyValueAtIndex(emails, 0);

    //    } else {

    //        email = @"[None]";

    //    }

    self.userEmail.text = email;
    self.myMessage.recipientEmail = email;
    CFRelease(emails);
    return NO;
}
Sid Holland
  • 2,871
  • 3
  • 27
  • 43

1 Answers1

4

This is example code comes directly from my book (http://www.apeth.com/iOSBook/ch31.html#_abpeoplepickernavigationcontroller):

- (BOOL)peoplePickerNavigationController:
        (ABPeoplePickerNavigationController *)peoplePicker
        shouldContinueAfterSelectingPerson:(ABRecordRef)person
        property:(ABPropertyID)property
        identifier:(ABMultiValueIdentifier)identifier {
    ABMultiValueRef emails = ABRecordCopyValue(person, property);
    CFIndex ix = ABMultiValueGetIndexForIdentifier(emails, identifier);
    CFStringRef email = ABMultiValueCopyValueAtIndex(emails, ix);
    NSLog(@"%@", email); // do something with the email here
    if (email) CFRelease(email);
    if (emails) CFRelease(emails);
    [self dismissViewControllerAnimated:YES completion:nil];
    return NO;
}
matt
  • 515,959
  • 87
  • 875
  • 1,141