I'm making a external function to check if user is already logged into Firebase.
My code is working, but in trying to ensure that current VC is dismissing in the end, I get an error.
My question is: How can i get the current VC or how can i use self. to reference the current VC that function is called?
class Helper{
static func checkIfLogged()  {
    Auth.auth().addStateDidChangeListener { auth, user in
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let controller = storyboard.instantiateViewController(withIdentifier: "HomeViewController")
        UIApplication.shared.keyWindow?.rootViewController = controller
        self.dismiss(animated: true, completion: nil) **** ERROR IS HERE ***
    }
}
}
                extension UIApplication{
class func getPresentedViewController() -> UIViewController? {
    var presentViewController = UIApplication.shared.keyWindow?.rootViewController
    while let pVC = presentViewController?.presentedViewController
    {
        presentViewController = pVC
    }
    return presentViewController
  }
}
just add this extension and call : UIApplication. getPresentedViewController()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With