With the introduction of UIAlertController in iOS8 a new era began where you could present modal controllers partially covering presenting controllers. But as with everything, it also brought new problems. Every view controller can only present one modal controller. And it becomes tricky when you need to show multiple alerts or messages with custom presentation at the same time.
We can start with single service for managing all the alerts and custom popups. This service will present all queued messages using app root controller.
If nothing is shown, present the modal controller. But what happens, when there is existing alert and you need to queue next message? This is put into controllers array and then…?
Obvious way is to call presentNext() in root controller every time when viewDidAppear() is called. But these event is only called when controller is added to view hierarchy. With modal popups root controllers view is not removed from view hierarchy… It stays visible under the presented popup…
So we need another method for pushing modal popups presentation. There is one view were every controller view will end up. Actually it’s a window.
By setting custom window as application window in app delegate, we can monitor for changes in view hierarchy. And when ever something is remove, try to present queued alert.
Tags: ios, ui, modal, custom