Reputation: 71
In iOS 8, the following was deprecated:
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
and now we are supposed to use:
-(void)peoplePickerNavigationController:didSelectPerson:
but this method automatically dismisses the people picker after the first selection where the old version did not. I have a routine that needs to record each name that the user picks one by one. I can re-display the people picker after each selection but it starts the contact list back at the first name.
I hope I explained this correctly. Anyone know how to keep the peoplepickernavigationcontroller from auto dismissing in iOS 8 like it used to do in ios7?
Upvotes: 7
Views: 2071
Reputation: 3343
In the documentation of ABPeoplePickerNavigationController, check out the comment of predicateForSelectionOfPerson.
// Optionally determines if a selected person should be returned to the app (predicate evaluates to TRUE),
// or if the selected person should be displayed (predicate evaluates to FALSE).
// If not set and -peoplePickerNavigationController:didSelectPerson: is implemented the selected person is returned to the app,
// or if not set and -peoplePickerNavigationController:didSelectPerson:identifier: is implemented the selected person is displayed.
//
@property(nonatomic,copy) NSPredicate *predicateForSelectionOfPerson NS_AVAILABLE_IOS(8_0);
So you need to set a predicate of FALSE, if you want to display the selected person.
if ([picker respondsToSelector:@selector(setPredicateForSelectionOfPerson:)])
{
picker.predicateForSelectionOfPerson = [NSPredicate predicateWithValue:NO];
}
Upvotes: 2
Reputation: 1008
I've found a solution to re-showing the people picker after selecting a property.
Implement the delegate method that handles when a person chooses a contact property (only called by iOS 8): The trick for me was to dismiss then picker, then immediately call my "show picker" method in the completion delegate (yes, a delegate within a delegate).
// Dismisses the people picker and shows the application when users tap Cancel.
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
[self.picker dismissViewControllerAnimated:NO completion:^{
NSLog(@"just dismissed the picker");
[self showPeoplePickerController];
}];
}
Make sure to init the people picker once if you want it to show up where it last left off. Hope this helps
here is my showPeoplePickerController method
#pragma mark Show all contacts
// Called when users tap "Display Picker" in the application. Displays a list of contacts and allows users to select a contact from that list.
-(void)showPeoplePickerController
{
picker.peoplePickerDelegate = self;
picker.delegate = self;
picker.visibleViewController.searchDisplayController.searchBar.delegate = self;
[self presentViewController:picker animated:NO completion:nil];
}
First initialize the picker. Note that there is an authorization method call required for contacts access in the first place
picker = [[ABPeoplePickerNavigationController alloc] init];
//have self prompt first, then based off answer prompt them with internal address book stuff or now
if(ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized)
{
// show picker UI if the user has granted access to their Contacts
[self showPeoplePickerController];
}
NOTES:
Upvotes: 1