0

I am trying to show ABPersonVIewController on PeoplePickerNavigationController. But it isn't working in iOS 8. Here is the code I have used.

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];

What could be the reason and how will I get around this issue.

Jean Paul
  • 2,389
  • 5
  • 27
  • 37
  • I am seeing this issue as well - only on iOS 8 devices, not in the simulator. The controller displays only the name, with no other properties. Anyone know of a workaround? – montuno Nov 11 '14 at 00:34

1 Answers1

0

This will allow you to open people picker and select information from the contact. I don't know what information you need but you get the idea.

- (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; }
abdiel.ramirez
  • 125
  • 2
  • 13