From 4b72b64f719f4fac5ddf39e78ff835c2017eb9a7 Mon Sep 17 00:00:00 2001 From: Brandon-T Date: Mon, 16 Oct 2023 09:30:29 -0400 Subject: [PATCH] Fix #8228: Switch to UIScene notifications (#8249) --- .../Browser/BrowserViewController.swift | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController.swift b/Sources/Brave/Frontend/Browser/BrowserViewController.swift index 529eef617c4..2992ab28065 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController.swift @@ -682,7 +682,11 @@ public class BrowserViewController: UIViewController { displayedPopoverController?.dismiss(animated: true) } - @objc func appDidEnterBackgroundNotification() { + @objc func sceneDidEnterBackgroundNotification(_ notification: NSNotification) { + guard let scene = notification.object as? UIScene, scene == currentScene else { + return + } + displayedPopoverController?.dismiss(animated: false) { self.updateDisplayedPopoverProperties = nil self.displayedPopoverController = nil @@ -706,7 +710,11 @@ public class BrowserViewController: UIViewController { toolbarVisibilityViewModel.toolbarState = .expanded } - @objc func appWillResignActiveNotification() { + @objc func sceneWillResignActiveNotification(_ notification: NSNotification) { + guard let scene = notification.object as? UIScene, scene == currentScene else { + return + } + tabManager.saveAllTabs() // Dismiss any popovers that might be visible @@ -739,7 +747,11 @@ public class BrowserViewController: UIViewController { } } - @objc func appDidBecomeActiveNotification() { + @objc func sceneDidBecomeActiveNotification(_ notification: NSNotification) { + guard let scene = notification.object as? UIScene, scene == currentScene else { + return + } + guard let tab = tabManager.selectedTab, tab.isPrivate else { return } @@ -823,14 +835,14 @@ public class BrowserViewController: UIViewController { NotificationCenter.default.do { $0.addObserver( - self, selector: #selector(appWillResignActiveNotification), - name: UIApplication.willResignActiveNotification, object: nil) + self, selector: #selector(sceneWillResignActiveNotification(_:)), + name: UIScene.willDeactivateNotification, object: nil) $0.addObserver( - self, selector: #selector(appDidBecomeActiveNotification), - name: UIApplication.didBecomeActiveNotification, object: nil) + self, selector: #selector(sceneDidBecomeActiveNotification(_:)), + name: UIScene.didActivateNotification, object: nil) $0.addObserver( - self, selector: #selector(appDidEnterBackgroundNotification), - name: UIApplication.didEnterBackgroundNotification, object: nil) + self, selector: #selector(sceneDidEnterBackgroundNotification), + name: UIScene.didEnterBackgroundNotification, object: nil) $0.addObserver( self, selector: #selector(appWillTerminateNotification), name: UIApplication.willTerminateNotification, object: nil)