ABPersonViewController 在推送到 PeoplePickerNavigationController 时未检索数据

Posted

技术标签:

【中文标题】ABPersonViewController 在推送到 PeoplePickerNavigationController 时未检索数据【英文标题】:ABPersonViewController not retrieving data when pushed into PeoplePickerNavigationController 【发布时间】:2014-09-30 04:21:37 【问题描述】:

我正在尝试在 PeoplePickerNavigationController 上显示 ABPersonVIewController。但它在 ios 8 中不起作用。这是我使用的代码。

ABPersonViewController *personVC = [[ABPersonViewController alloc] init];
personVC.addressBook = peoplePicker.addressBook;
ABRecordID displayedPerson = contactId;
personVC.displayedPerson = ABAddressBookGetPersonWithRecordID(peoplePicker.addressBook, displayedPerson);
[peoplePicker pushViewController: personVC animated:NO];
[self presentViewController: peoplePicker animated:NO completion:nil];

可能是什么原因以及我将如何解决这个问题。

【问题讨论】:

我也看到了这个问题 - 仅在 iOS 8 设备上,而不是在模拟器中。控制器仅显示名称,没有其他属性。有人知道解决方法吗? 【参考方案1】:

这将允许您打开人员选择器并从联系人中选择信息。我不知道你需要什么信息,但你明白了。

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier 
            [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person property:property identifier:identifier];


        NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(person));
        self.nameField.text = [NSString stringWithFormat:@"%@", contactName ? contactName : @"No Name"];


        ABMultiValueRef phoneRecord = ABRecordCopyValue(person, kABPersonPhoneProperty);
        CFStringRef phoneNumber = ABMultiValueCopyValueAtIndex(phoneRecord, 0);
        self.phoneField.text = (__bridge_transfer NSString *)phoneNumber;
        CFRelease(phoneRecord);


        ABMultiValueRef email = ABRecordCopyValue(person, kABPersonEmailProperty);
        CFStringRef emailField = ABMultiValueCopyValueAtIndex(email, 0);
        self.emailField.text = (__bridge_transfer NSString *)emailField;
        CFRelease(email);

        CFDataRef  photo = ABPersonCopyImageData(person);
        UIImage* image = [UIImage imageWithData:(__bridge NSData*)photo];
        if(photo)
            CFRelease(photo);
        if(image)
            self.myImageView.image = image;
        [self dismissViewControllerAnimated:YES completion:nil];
        return NO;
    



       -(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
             shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property
                                     identifier:(ABMultiValueIdentifier)identifier
        
            [self dismissViewControllerAnimated:YES completion:nil];
            return NO; 

【讨论】:

以上是关于ABPersonViewController 在推送到 PeoplePickerNavigationController 时未检索数据的主要内容,如果未能解决你的问题,请参考以下文章

为啥我的 ABPersonViewController 没有显示所有属性?

如何在 iPhone 的横向模式下停止 ABPersonViewController 和 ABNewPersonViewController 的旋转

带有可编辑 ABPersonViewController 的 ABPeoplePickerNavigationController

使用 ABPersonViewController 在 iPhone 应用程序中自定义联系人显示

在 iOS8 上将 ABPersonViewController 推送到 ABPeoplePickerNavigationController

如何为 A Person View Controller 的导航栏添加返回按钮?