1

我没有发现 Apple 的文档对于通过人员选择器实际获取数据很有帮助,而且互联网上似乎没有太多其他信息 :( 我假设我需要在这个函数中获取电子邮件:

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

}

我可以在那里输入什么来获取所选人员的电子邮件?

4

2 回答 2

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;
于 2012-03-30T03:59:05.547 回答
0

利用

ABMultiValueRef emails = ABRecordCopyValue(record, kABPersonEmailProperty);

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

编辑——这应该给你电子邮件

CFStringRef emailId = ABMultiValueCopyValueAtIndex(emails, identifier);
于 2011-07-18T17:43:34.533 回答