Swift: prevent closing ABPeoplePickerNavigationController

I would like to find a way so that if the user clicks the Cancel button (which, in my opinion, cannot be deleted) in the ABPeoplePickerNavigationController , the view controller will either not close or will automatically resume.

For example, given the following:

 var picker = ABPeoplePickerNavigationController() picker.peoplePickerDelegate = self self.presentViewController(picker, animated: true, completion: nil) 

I would like to do something like:

 if (self.presentedViewController != picker && !userContinuedPastPicker) { //where userContinuedPastPicker is a boolean set to false //in a delegate method called when the user clicks on an a contact //(meaning the user didn't press the cancel button but instead clicked on a contact) //create and present a UIAlertAction informing the user they must select a contact //present picker again self.presentViewController(picker, animated: true, completion: nil) } 

This does not work; however, since the if will not β€œwait” until the user presses the cancel button or presses the contact.

+7
ios swift uinavigationcontroller abaddressbook presentviewcontroller
source share
1 answer

I'm not sure there is a way to remove the cancel button or prevent it from working, but you can answer the delegate func peoplePickerNavigationControllerDidCancel(_ peoplePicker: ABPeoplePickerNavigationController!) To handle the case when the cancel button is clicked.

I would recommend, and not immediately restart the collector, you opened a warning telling the user that they need to choose someone, then open it back. He may feel broken if they are canceled, and he immediately opens.

Reference

Editing:
The presentation of a warning or collector probably needs to be delayed long enough for the previous collector to close. dispatch_after

+4
source share

All Articles