fix alert not finding right view controller

This commit is contained in:
leminlimez committed 2025-06-18 22:44:13 -04:00
1 parent a1ce92f3eb
commit a9cfe59c49
3 files changed
+7 -5

No files matched your search

+4 -2
View File
@@ -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
}