ABPersonViewController在被推入PeoplePickerNavigationController时未



我正试图在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];

原因是什么?我将如何解决这个问题。

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

- (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; }

相关内容

  • 没有找到相关文章

最新更新