     open func presentViewController(_ viewController: UIViewController, animated: Bool, completion: (() -> Void)?) {
         guard let rootVC = self.window?.rootViewController else { return }
         var topViewController: UIViewController = rootVC
-        while (topViewController.presentedViewController != nil) {
-            topViewController = topViewController.presentedViewController!
+        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)
     }

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


    private weak var passcodeViewController: UIViewController?
    
    private var backgroundTimestamp: Date?
    public var backgroundTimeout: TimeInterval = 5 * 60
    
    /**
     Is the passcode blocking?
     */
