How to make peoplePickerNavigationController automatically deviate

In iOS 8, the following was deprecated:

- (BOOL) peoplePickerNavigationController: (ABPeoplePickerNavigationController *) peoplePicker shouldContinueAfterSelectingPerson: (ABRecordRef) person

and now we must use:

- (invalid) peoplePickerNavigationController: didSelectPerson:

but this method automatically rejects the people picker after the first selection, where there was no old version. I have a program that should record every name that the user selects one after another. I can re-display the people picker after each selection, but it starts the contact list with the first name.

I hope I explained it correctly. Does anyone know how to keep peoplepickernavigation dispatcher from automatically rejecting in iOS 8, as it did in ios7?

+5
source share
2 answers

In the ABPeoplePickerNavigationController documentation, review the predicateForSelectionOfPerson comment.

// 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); 

Therefore, you need to set the FALSE predicate if you want to display the selected person.

  if ([picker respondsToSelector:@selector(setPredicateForSelectionOfPerson:)]) { picker.predicateForSelectionOfPerson = [NSPredicate predicateWithValue:NO]; } 
+2
source

I found a solution to redisplay the people picker after selecting a property.

Implement a delegate method that handles when a person selects a contact property (iOS 8 only): the trick for me was to remove it, then immediately call my "show picker" method in the completion deletion (yes, the delegate in the 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]; }]; } 

Be sure to run the people picker once if you want it to appear where it was last. 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]; } 

Initialize the collector first. Please note that first of all, you need to call the authorization method necessary to access your contacts

 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:

  • Previously, I ran the people picker when loading a view. once.
  • setting the "animated" NO option when introducing and firing the controller helps make the transition smoother.
+1
source

Source: https://habr.com/ru/post/1203059/


All Articles