ABPeoplePickerNavigationControllerDelegate:shouldContinueAfterSelectingPerson使用电子邮件地址提供错误的ABMultiValue id

时间:2013-09-12 23:46:51

标签: iphone ios abaddressbook

当我选择具有多个电话号码的联系人并选择其中一个电话号码时,这可以正常工作,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));
}

1 个答案:

答案 0 :(得分: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;
}