ChemDev
ChemDev

Reputation: 837

ABPeoplePickerNavigationController Delegate Not Working

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.

Upvotes: 0

Views: 767

Answers (2)

Raees Madathil
Raees Madathil

Reputation: 291

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

Upvotes: 0

Aaron Brager
Aaron Brager

Reputation: 66234

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.)

Upvotes: 5

Related Questions