iphone - ABPeoplePickerNavigationControllerDelegate:shouldContinueAfterSelectingPerson提供带有电子邮件地址的错误ABMultiValue ID

标签 iphone ios abaddressbook

当我选择具有多个电话号码的联系人并选择他们的电话号码之一时,此方法工作正常,收件人地址设置为选定的电话号码。但是,当我从具有多个电子邮件地址的联系人中选择电子邮件地址时,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));
}

最佳答案

这两种方法可能有助于您获取所选人员的电子邮件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;
}

关于iphone - ABPeoplePickerNavigationControllerDelegate:shouldContinueAfterSelectingPerson提供带有电子邮件地址的错误ABMultiValue ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18776005/

相关文章:

iOS 构建错误 - 多个构建命令

c - 在 Mac OS X 上获取默认电子邮件地址

iphone - 为iOS构建静态库

ios - 缩放和 ScrollView

ios - 让用户随时了解其位置并在 iOS 后台运行的应用程序?

iphone - 当 UIButton 被拖动到屏幕的某个点时触发事件? objective-c

ios - 添加 kABPersonAddressProperty 时 ABAddressBookSave 崩溃

iphone - 当 recordId 不可用时,ABAddressBookGetPersonWithRecordID 会使应用程序崩溃

iphone - 为什么我的 iPhone 应用程序的图标在构建后被划掉?

iphone - UILocalNotification 没有被取消