fix alert not finding right view controller
This commit is contained in:
1 parent
a1ce92f3eb
commit
a9cfe59c49
3 files changed
+7
-5
No files matched your search
@@ -9,6 +9,7 @@ import UIKit
|
||||
|
||||
// credit: sourcelocation & TrollTools
|
||||
var currentUIAlertController: UIAlertController?
|
||||
var lastDismissTitle: String?
|
||||
|
||||
|
||||
fileprivate let errorString = NSLocalizedString("Error", comment: "")
|
||||
@@ -19,6 +20,7 @@ extension UIApplication {
|
||||
|
||||
func dismissAlert(animated: Bool) {
|
||||
DispatchQueue.main.async {
|
||||
lastDismissTitle = currentUIAlertController?.title
|
||||
currentUIAlertController?.dismiss(animated: animated)
|
||||
}
|
||||
}
|
||||
@@ -60,8 +62,8 @@ extension UIApplication {
|
||||
}
|
||||
|
||||
func present(alert: UIAlertController) {
|
||||
if var topController = self.windows[0].rootViewController {
|
||||
while let presentedViewController = topController.presentedViewController {
|
||||
if let window = UIApplication.shared.connectedScenes.map({ $0 as? UIWindowScene }).compactMap({ $0 }).first?.windows.first, var topController = window.rootViewController {
|
||||
while let presentedViewController = topController.presentedViewController, presentedViewController.title != lastDismissTitle {
|
||||
topController = presentedViewController
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user