How to keep peoplePickerNavigationController from automatically dismissing
Asked Answered
L

2

7

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?

Lenlena answered 21/9, 2014 at 1:36 Comment(1)
@NikitaIvaniushchenko check out my answer belowBalfore
B
2

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];
}
Balfore answered 19/1, 2015 at 9:1 Comment(1)
Anyway, it's not the same. Before that, i had a chance to push another view controller into the same navigation stack, but now ABPeoplePickerNavigationController is automatically dismissed.Climatology
G
1

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:

  • I previously initiated people picker when the view loaded. once.
  • setting the "animated" option to NO on presenting and dismissing controller helps make transition smoother.
Granese answered 5/10, 2014 at 5:44 Comment(2)
not quite working. Maybe I'm doing something wrong. How are you initializing the picker in the view load?Lenlena
@JackRomano what or where is your code breaking? any more info?Granese

© 2022 - 2024 — McMap. All rights reserved.