How to present a UIAlertController from controller in main window and make it appear above a controller in an overlaid UIWindow

In my app I have a second UIWindow that appears above the main window in order to present a small floating view controller that appears above other view controllers in the app. Touches pass through the top window to the lower (main) window. Whenever the main window presents a UIAlertController the alert appears behind the floating view controller in my top window. I was under the impression that alerts are presented in their own window with a window level of UIWindowLevelAlert, which should place them above any controller that belongs to a window at UIWindowLevelNormal (which is the level of both my main window and top window).


How can I get alerts presented by my lower (main) window to appear above controllers in my overlay window?

Replies

So you have firstWindow, below secondWindow

Where do you call the alert ? Inside secondWindowController ?


May have a look here

https://stackoverflow.com/questions/26554894/how-to-present-uialertcontroller-when-not-in-a-view-controller


extension UIAlertController {

    func presentInOwnWindow(animated: Bool, completion: (() -> Void)?) {
        let alertWindow = UIWindow(frame: UIScreen.main.bounds)
        alertWindow.rootViewController = UIViewController()
        alertWindow.windowLevel = UIWindowLevelAlert + 1;
        alertWindow.makeKeyAndVisible()
        alertWindow.rootViewController?.present(self, animated: animated, completion: completion)
    }
}

Example usage:


let alertController = UIAlertController(title: "", message: "", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Close", style: .cancel, handler: nil))
alertController.presentInOwnWindow(animated: true, completion: {
    print("completed")
})

Would this work if use it from my Share Controller to tell the user that the act of sharing occurred or succeeded when the user uses my share extension by telling an app to share with my app?