如何从ABPeoplePickerView中的选定ABPerson获取电子邮件

时间:2011-02-26 21:06:42

标签: objective-c cocoa abpeoplepickerview

我需要从我的Cocoa应用程序访问所选人员的电子邮件。我已将ABPeoplePickerView放置在主窗口上,并通过[peoplePicker selectedRecords]获得了一个选定人员列表。如何访问ABPerson对象的电子邮件字段?

2 个答案:

答案 0 :(得分:2)

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
     shouldContinueAfterSelectingPerson:(ABRecordRef)person 
                               property:(ABPropertyID)property 
                             identifier:(ABMultiValueIdentifier)identifier
{
    NSString *email = nil;
    ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
    if(emails){
        email = (NSString *) ABMultiValueCopyValueAtIndex(emails,0);
        [email autorelease];
    }

    [self dismissModalViewControllerAnimated:YES];
    emaillabel.text = email;
    return YES;
}

答案 1 :(得分:0)

我假设您的ABPerson对象由person引用:

ABRecordCopyValue( ( ABRecordRef ) person, kABEmailProperty );