From 57784d3354a1c2a847b548fbb3d1f3f5a43b0f1a Mon Sep 17 00:00:00 2001 From: adam1929 <103995671+adam1929@users.noreply.github.com> Date: Mon, 18 Dec 2023 16:01:06 +0100 Subject: [PATCH] Shows alert for opened push only if could - example app --- ExponeaSDK/Example/AppDelegate.swift | 32 +++++++++++++++++----------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/ExponeaSDK/Example/AppDelegate.swift b/ExponeaSDK/Example/AppDelegate.swift index c0f37e85..5109f530 100644 --- a/ExponeaSDK/Example/AppDelegate.swift +++ b/ExponeaSDK/Example/AppDelegate.swift @@ -90,21 +90,27 @@ class AppDelegate: ExponeaAppDelegate { extension AppDelegate { func showAlert(_ title: String, _ message: String?) { - let alert = UIAlertController(title: title, message: message ?? "no body", preferredStyle: .alert) - alert.addAction( - UIAlertAction( - title: "Ok", - style: .default, - handler: { [weak self] _ in self?.alertWindow?.isHidden = true } + DispatchQueue.main.sync { [weak self] in + guard let self else { + Exponea.logger.log(.warning, message: "Alert not shown because of lost frame") + return + } + let alert = UIAlertController(title: title, message: message ?? "no body", preferredStyle: .alert) + alert.addAction( + UIAlertAction( + title: "Ok", + style: .default, + handler: { [weak self] _ in self?.alertWindow?.isHidden = true } + ) ) - ) - if alertWindow == nil { - alertWindow = UIWindow(frame: UIScreen.main.bounds) - alertWindow?.rootViewController = UIViewController() - alertWindow?.windowLevel = .alert + 1 + if alertWindow == nil { + alertWindow = UIWindow(frame: UIScreen.main.bounds) + alertWindow?.rootViewController = UIViewController() + alertWindow?.windowLevel = .alert + 1 + } + alertWindow?.makeKeyAndVisible() + alertWindow?.rootViewController?.present(alert, animated: true, completion: nil) } - alertWindow?.makeKeyAndVisible() - alertWindow?.rootViewController?.present(alert, animated: true, completion: nil) } }