【问题标题】:ABPeoplePickerNavigationControllerDelegate: shouldContinueAfterSelectingPerson giving bad ABMultiValue id with email addressesABPeoplePickerNavigationControllerDelegate: shouldContinueAfterSelectingPerson 提供错误的 ABMultiValue id 和电子邮件地址
【发布时间】:2013-09-12 23:46:50
【问题描述】:

当我选择具有多个电话号码的联系人并选择他们的一个电话号码时,这很好用,收件人地址设置为所选电话号码。但是,当我从具有多个电子邮件地址的联系人中选择电子邮件地址时,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));
}

【问题讨论】:

    标签: iphone ios abaddressbook


    【解决方案1】:

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

    【讨论】:

    • 首先,让我很抱歉花了这么长时间才回复。我没有收到电子邮件通知,忘记了我发布了这个。您的代码有效,但现在我的代码突然也有效(没有变化)。我将把它归结为一个在 GM 中神奇地修复的 iOS 7 错误(或者我的其他代码中某些错误的神秘副作用)。我很困惑为什么定义为 ABMultiValueIdentifier 的参数可以直接用作 ABMultiValueIndex,但作为一个长期的 ABAddressBook 开发人员,我知道假设 ABAddressBook API 具有逻辑意义是多么愚蠢。感谢您的帮助。
    • @RandyHill :太好了,你终于让一切正常了,因为一天结束时,其他一切都不重要。并感谢您接受我的回答。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-13
    • 1970-01-01
    相关资源
    最近更新 更多