From 5cf6e65323f488e533dacf6f3aef8efbc0df4643 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 16 Apr 2018 17:39:13 -0400 Subject: [PATCH] Fix screen lock alerts. --- Signal/src/util/OWSScreenLockUI.m | 3 ++- SignalMessaging/views/OWSAlerts.swift | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Signal/src/util/OWSScreenLockUI.m b/Signal/src/util/OWSScreenLockUI.m index 16205ba6e..a1f2ecb21 100644 --- a/Signal/src/util/OWSScreenLockUI.m +++ b/Signal/src/util/OWSScreenLockUI.m @@ -393,7 +393,8 @@ const UIWindowLevel UIWindowLevel_Background = -1.f; buttonAction:^(UIAlertAction *action) { // After the alert, re-show the unlock UI. [self ensureUI]; - }]; + } + fromViewController:self.screenBlockingViewController]; } // 'Screen Blocking' window obscures the app screen: diff --git a/SignalMessaging/views/OWSAlerts.swift b/SignalMessaging/views/OWSAlerts.swift index 105c59758..344bff32f 100644 --- a/SignalMessaging/views/OWSAlerts.swift +++ b/SignalMessaging/views/OWSAlerts.swift @@ -34,11 +34,20 @@ import Foundation @objc public class func showAlert(title: String?, message: String? = nil, buttonTitle: String? = nil, buttonAction: ((UIAlertAction) -> Void)? = nil) { + guard let fromViewController = CurrentAppContext().frontmostViewController() else { + return + } + showAlert(title: title, message: message, buttonTitle: buttonTitle, buttonAction: buttonAction, + fromViewController: fromViewController) + } + + @objc + public class func showAlert(title: String?, message: String? = nil, buttonTitle: String? = nil, buttonAction: ((UIAlertAction) -> Void)? = nil, fromViewController: UIViewController?) { let actionTitle = buttonTitle ?? NSLocalizedString("OK", comment: "") let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) alert.addAction(UIAlertAction(title: actionTitle, style: .default, handler: buttonAction)) - CurrentAppContext().frontmostViewController()?.present(alert, animated: true, completion: nil) + fromViewController?.present(alert, animated: true, completion: nil) } @objc