I would like to do some actions and present some UI right before and right after any UIAlertController dismisses itself (animation is finished) due to user tapping one of the alert's buttons.
How can I get notified that user pressed some button in my UIAlertController and it is going to be dismissed and then is dismissed?
In docs it is advised against subclassing UIAlertController. I still have tried my luck subclassing, thinking that maybe it internally calls func dismiss(animated flag: Bool, completion: (() -> Void)? = nil)
on itself. Something like self.dismiss(...
, but it doesn't seem to be the case on iOS10.
I have also tried to add 'manual' dismissing into UIAlertAction handler:
let alert = UIAlertController.init(...
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: { action in
alert.dismiss(animated: true, completion: {
print("Dismissed")
})
})
alert.addAction(defaultAction)
But it seems that alert is dismissed after button press but before calling handler. Anyhow it doesn't work as well. Even if it worked it would be a bit bothersome to remember to add my code into each and every UIAlertAction handler.
I would appreciate any ideas.