From a9cfe59c495792f36110d81d05f96b6520e0e054 Mon Sep 17 00:00:00 2001 From: leminlimez <59540996+leminlimez@users.noreply.github.com> Date: Wed, 18 Jun 2025 22:44:13 -0400 Subject: [PATCH] fix alert not finding right view controller --- Pocket Poster.xcodeproj/project.pbxproj | 4 ++-- Pocket Poster/Extensions/Alert++.swift | 6 ++++-- Pocket Poster/Views/ContentView.swift | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Pocket Poster.xcodeproj/project.pbxproj b/Pocket Poster.xcodeproj/project.pbxproj index a2e0def..07e4182 100644 --- a/Pocket Poster.xcodeproj/project.pbxproj +++ b/Pocket Poster.xcodeproj/project.pbxproj @@ -264,7 +264,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 5; DEVELOPMENT_ASSET_PATHS = "\"Pocket Poster/Preview Content\""; DEVELOPMENT_TEAM = 2P4CP47H76; ENABLE_PREVIEWS = YES; @@ -296,7 +296,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 5; DEVELOPMENT_ASSET_PATHS = "\"Pocket Poster/Preview Content\""; DEVELOPMENT_TEAM = 2P4CP47H76; ENABLE_PREVIEWS = YES; diff --git a/Pocket Poster/Extensions/Alert++.swift b/Pocket Poster/Extensions/Alert++.swift index f6bd495..adb3f31 100644 --- a/Pocket Poster/Extensions/Alert++.swift +++ b/Pocket Poster/Extensions/Alert++.swift @@ -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 } diff --git a/Pocket Poster/Views/ContentView.swift b/Pocket Poster/Views/ContentView.swift index 67e17d6..576c748 100644 --- a/Pocket Poster/Views/ContentView.swift +++ b/Pocket Poster/Views/ContentView.swift @@ -73,9 +73,9 @@ struct ContentView: View { SymHandler.cleanup() // just to be extra sure try? FileManager.default.removeItem(at: pbManager.getTendiesStoreURL()) UIApplication.shared.dismissAlert(animated: false) - Haptic.shared.notify(.success) DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: { pbManager.selectedTendies.removeAll() + Haptic.shared.notify(.success) UIApplication.shared.confirmAlert(title: NSLocalizedString("Success!", comment: ""), body: NSLocalizedString("The PosterBoard app will now open. Please close it from the app switcher.", comment: ""), onOK: { if !pbManager.openPosterBoard() { UIApplication.shared.confirmAlert(title: NSLocalizedString("Falling Back to Shortcut", comment: ""), body: NSLocalizedString("PosterBoard failed to open directly. The fallback shortcut will now be opened.", comment: ""), onOK: {