如何使用ABPeoplePicker发送电子邮件?

时间:2011-07-18 17:27:58

标签: iphone ios xcode abpeoplepickerview

我发现Apple的文档对于实际获取人员选择器的数据非常有帮助,并且互联网上似乎没有太多其他信息:(我假设我需要在此功能中收到电子邮件:< / p>

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

}

我可以在那里收到所选人员的电子邮件?

2 个答案:

答案 0 :(得分:4)

Kal回答实际上是不准确的 - 即因为“ABMultiValueCopyValueAtIndex”采用索引而非标识符。

标识符值是静态的(如枚举)

  • “家庭电子邮件”始终为“0”
  • “工作电子邮件”始终为“1”。

因此,当选择的人只存储1封电子邮件时,它会崩溃,这是一个“工作电子邮件”。由于标识符为“1”,但我们需要索引“0”。

幸运的是,我们可以使用以下来获取索引:

int index = ABMultiValueGetIndexForIdentifier(emails, identifier);

代码:

if (property == kABPersonEmailProperty) {

    ABMultiValueRef emails = ABRecordCopyValue(person, property);

    NSString *count = [NSString stringWithFormat:@"Count: %d Identifier: %d", ABMultiValueGetCount(emails), identifier];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:count delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];

    if(ABMultiValueGetCount(emails) > 0)
    {
        int index = ABMultiValueGetIndexForIdentifier(emails, identifier);
        CFStringRef emailTypeSelected = ABMultiValueCopyLabelAtIndex(emails, index);
        CFStringRef emailTypeSelectedLocalized = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(emails, index));
        CFStringRef emailValueSelected = ABMultiValueCopyValueAtIndex(emails, index);

        self.lblEmailType.text = (NSString *) emailTypeSelected;
        self.lblEmailTypeLocalized.text = (NSString *) emailTypeSelectedLocalized;
        self.lblEmailValue.text = (NSString *) emailValueSelected;
    }

    [ self dismissModalViewControllerAnimated:YES ];
    return NO;
}

return YES;

答案 1 :(得分:0)

使用

ABMultiValueRef emails = ABRecordCopyValue(record, kABPersonEmailProperty);

之后,您可以使用ABMultiValueRefs API方法调用来获取电子邮件地址。

编辑 - 这应该会给你发电子邮件

CFStringRef emailId = ABMultiValueCopyValueAtIndex(emails, identifier);