0

Presenting the people picker

ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
peoplePicker.allowsActions = YES;
peoplePicker.allowsEditing = NO;
peoplePicker.peoplePickerDelegate = self;
[self presentViewController:peoplePicker animated:YES completion:nil];

Implementing the ABPeoplePickerNavigationControllerDelegate in iOS 7

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
  ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
  personViewController.displayedPerson = person;
  [peoplePicker pushViewController:personViewController animated:YES];
  return NO;
}

So far so good. The person view controller is presented as expected. iOS7 method returns a value - one could return NO in order to make sure the people picker remains open. In iOS8 the above delegate method was deprecated and new method must be implemented:

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person {
  ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
  personViewController.displayedPerson = person;
  [peoplePicker pushViewController:personViewController animated:YES];
}

The person view controller is pushed to the people picker but after a fraction of a second the people picker is dismissed (together with the person view controller).

Is there a way to prevent the people picker from dismissing on iOS8? Any other suggestions?

tonymontana
  • 5,728
  • 4
  • 34
  • 53
  • 1
    What you were doing was always wrong. It was never correct to push ABPersonViewController onto ABPeoplePickerNavigationController like that. Rethink your interface. – matt Oct 30 '14 at 20:12
  • Fundamentally, what are you trying to achieve? Why not let the people picker show you the person itself? – Rob Oct 30 '14 at 20:46
  • 1
    @Rob I want the ABPersonViewController to display the action buttons which are not displayed by default. – tonymontana Oct 30 '14 at 20:49
  • What if you want to display a custom detail view instead of the default view? It wouldn't be so bad if apple had used the public dismissModal method instead of a private API to dismiss the controller. Sloppy... – Kirby Todd Oct 31 '14 at 04:17
  • @matt Why it wrong was wrong on iOS 7? Can you please elaborate? – tonymontana Nov 04 '14 at 12:25

3 Answers3

0
-(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person
{ 
    [self dismissViewControllerAnimated:NO completion:^{
      ABPersonViewController *personController = [[ABPersonViewController alloc] init];

      [personController setDisplayedPerson:person];
      [personController setPersonViewDelegate:self];
      [personController setAllowsEditing:NO];
      personController.displayedProperties = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty], nil];

      [self.navigationController pushViewController:personController animated:YES];
    }];
}
tonymontana
  • 5,728
  • 4
  • 34
  • 53
0

How about using presentViewController instead pushViewController ... in Xcode 6 it says that pushViewController is deprecated and I see you're trying to implement it in iOS8 so give it a try ... Something like this line:

[peoplePicker presentViewController: personViewController animated: YES completion: nil];
Hristo Atanasov
  • 1,236
  • 2
  • 18
  • 25
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]; }
Wei Zhang
  • 110
  • 1
  • 7