0

My goal is to allow the user to import contact details (phone, name and email) from contacts. When I set up an ABPeoplePickerNavigationController and set the delegate to self, the delegate methods are not being called. The people picker view is being displayed Here is my code:

-(IBAction)importFromContacts:(id)sender
{

    ABPeoplePickerNavigationController *newNavController = [[ABPeoplePickerNavigationController alloc] init];
    newNavController.delegate = self;
    [self presentViewController:newNavController animated:YES completion:nil];

}

-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
    NSLog(@"cancel");
    [self dismissViewControllerAnimated:YES completion:nil];
}

What am I missing? I would also like to add that the class ABPeoplePicker does not seem to be part of the UIAddressBook framework anymore. It is not in the docs either.

ChemDev
  • 827
  • 1
  • 8
  • 23

2 Answers2

5

You're setting delegate, which describes the object that should handle UINavigationController's delegate methods.

Change

newNavController.delegate = self;

to

newNavController.peoplePickerDelegate = self;

(As described in the Class Reference, ABPeoplePickerNavigationController is a subclass of UINavigationController. It's not out of the ordinary for an object to have multiple delegates, even within the same class.)

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
0

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

Raees Madathil
  • 291
  • 1
  • 3
  • 14