-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;
}
4

1 回答 1

4

这是示例代码直接来自我的书(http://www.aeth.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;
}
于 2013-05-06T02:12:52.837 回答