0

i have a question about the ABPersonViewController. I use the ABPeoplePickerNavigationControllerDelegate to show the people picker (list of contacts). I want to show a ABPersonViewController when i select a person. The problem is that the ABPersonViewController disapear after selecting the person. In detail -> i select a person -> ABPersonViewController appears (with the correct properties) -> ABPersonViewController dispear immediately and the complete peoplepicker also. I think the problem is that i push the PeoplePicker away.

I read a lot in tutorials but i dont get it. I am currently develop for IOS 8.

Most of the tutorials call the ABPersonViewController in a diffrent method of peoplepicker but if i call it in another delegate method it doesnt work.

Here is my code:

@interface ViewController : UIViewController<ABPeoplePickerNavigationControllerDelegate, ABPersonViewControllerDelegate>

- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {

    ABPersonViewController *picker = [[ABPersonViewController alloc] init];
    picker.personViewDelegate = self;
    picker.displayedPerson = person;
    picker.displayedProperties = peoplePicker.displayedProperties;
    picker.allowsActions = YES;
    [peoplePicker pushViewController:picker animated:YES];
    return NO;
}

Thank you in advance.

Greetings

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Yetispapa
  • 2,174
  • 2
  • 30
  • 52
  • 1
    Why are you showing your own `ABPersonViewController`? The `ABPeoplePickerNavigationController` will show the contact details for you automatically if your `ABPeoplePickerNavigationControllerDelegate` are implemented properly. – rmaddy Oct 04 '14 at 18:28
  • Ok then is my question how can I set the properties for the PersonViewController and how can I get the selected property of the PersonViewController – Yetispapa Oct 04 '14 at 18:40
  • 1
    Look at the `displayedProperties` property of `ABPeoplePickerNavigationController`. And implement the right delegate methods to be notified when a property is selected for a specific contact. – rmaddy Oct 04 '14 at 18:42
  • Ok sounds hops. I will try it (: – Yetispapa Oct 04 '14 at 20:06

1 Answers1

0

In iOS8, you will need to add code as below when you initialise the ABPeoplePickerNavigationController, otherwise the peoplePickerNavigationController will dismiss right away after you select a contact.

if(IOS8_OR_LATER){
    peoplePicker.predicateForSelectionOfPerson = [NSPredicate predicateWithValue:false];
}

Also, for iOS 8, use

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier 

or

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person

Instead of

shouldContinueAfterSelectingPerson

Because this method has deprecated in iOS8

Wei Zhang
  • 110
  • 1
  • 7