         return true
     }
     
-    open func applicationWillResignActive(_ application: UIApplication) {
+    open func applicationDidEnterBackground(_ application: UIApplication) {
         if shouldShowPasscode() {
             // Hide content so it doesn't appear in the app switcher.
             rootViewController?.contentHidden = true
-        }
-        
+            self.backgroundTimestamp = Date()
+        }
+    }
+    
+    open func applicationWillResignActive(_ application: UIApplication) {
         // Save any outstanding clientData profile item updates to Bridge.
         SBAClientDataProfileItem.updateChangesToBridge()
     }

    }
    
    open func applicationWillEnterForeground(_ application: UIApplication) {
        lockScreen()
    }
    
    open func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {

    open func presentViewController(_ viewController: UIViewController, animated: Bool, completion: (() -> Void)?) {
        guard let rootVC = self.window?.rootViewController else { return }
        var topViewController: UIViewController = rootVC
        while let presentedVC = topViewController.presentedViewController {
            if presentedVC.modalPresentationStyle != .fullScreen {
                presentedVC.dismiss(animated: false, completion: nil)
                break
            }
            else {
                topViewController = presentedVC
            }
        }
        topViewController.present(viewController, animated: animated, completion: completion)
    }
