1

当我选择具有多个电话号码的联系人并选择他们的一个电话号码时,这很好用,recipientAddress 设置为所选电话号码。但是,当我从具有多个电子邮件地址的联系人中选择电子邮件地址时,ABMultiValueIdentifier 为零,它转换为索引为零,这始终是联系人中的最后一封电子邮件,无论我选择了哪一个。

我一定是做错了很尴尬的事情,而且很容易被发现,所以请通过暴露我的愚蠢来让自己看起来很棒。

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
    @try {
        [eta addRecipient: person : property: identifier];
    }
    @catch (NSException *exception) {
        errExcLog(exception);
    }
    return NO;
}

- (void) addRecipient : (ABRecordRef) person : (ABPropertyID) property : (ABMultiValueIdentifier)identifier {
    ABMultiValueRef mvPropertyRef = ABRecordCopyValue(person,  property);
    int propertyIndex = ABMultiValueGetIndexForIdentifier( mvPropertyRef,  identifier);
    NSString *recipientAddress = (__bridge NSString *)(ABMultiValueCopyValueAtIndex( mvPropertyRef,  propertyIndex));
}
4

1 回答 1

4

这两种方法可能会帮助您获取所选人员的电子邮件 ID

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
  shouldContinueAfterSelectingPerson:(ABRecordRef)person
                            property:(ABPropertyID)property
                          identifier:(ABMultiValueIdentifier)identifier
{
    ABPersonViewController *controller = [[ABPersonViewController alloc] init];
    controller.displayedPerson = person;
    controller.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonEmailProperty]];
    controller.personViewDelegate = self;
    [peoplePicker pushViewController:controller animated:YES];
    [controller release];
    return NO;
}

-(BOOL)personViewController:(ABPersonViewController *)personViewController
                shouldPerformDefaultActionForPerson:(ABRecordRef)person
                property:(ABPropertyID)property
              identifier:(ABMultiValueIdentifier)identifierForValue
{
    ABMutableMultiValueRef multiEmail = ABRecordCopyValue(person, property);

    NSString *emailAddress = (NSString *) ABMultiValueCopyValueAtIndex(multiEmail, identifierForValue);

    NSLog(@"strEmail %@",emailAddress);

    ABPeoplePickerNavigationController *peoplePicker = (ABPeoplePickerNavigationController *)personViewController.navigationController;
    [peoplePicker dismissViewControllerAnimated:YES completion:nil];
    return NO;
}
于 2013-09-13T04:38:25.897 回答