The app I'm working on has a main view controller, which is presenting different view controllers modally. These view controllers may present their own child view controllers modally.
At random times the main view controller may receive a notification to present a message (via message view controller) to the user, but the message view controller should not be presented until all other currently presented view controllers are dismissed.
Is there a reliable way for the main view controller to figure out when the modally presented view controller and its children are dismissed?
I've tried overriding the dismiss(animated:completion:)
in the main view controller, but it is not called if the modally presented view controller calls self.dismiss(animated:completion:)
. I've also tried with overriding viewDidAppear(_:)
in the main view controller, but it is not called if the modally presented view controller is presented with presentation style .overFullScreen
.
Any ideas?
Edit: I'm not asking how to figure out if the main view controller is topmost, I'm asking how can the view controller know when it becomes the topmost view controller.