2019-05-07
How do I segue from AppDelegate after auth from googleSignIn?
源自: stackoverflow
问题

Will not allow me to segue to another view controller from the app delegate file

I have tried to presentViewController

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        if let authentication = user.authentication {
            let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)

            Auth.auth().signInAndRetrieveData(with: credential) { (authResult, error) in
                if error != nil {
                    print(error!)
                } else{
                    print("user successfully signed in through GOOGLE! uid:\(Auth.auth().currentUser!.uid)")
                    print("signed in through AppDelegate")
                    performSegue(withIdentifier: "goToUsers", sender: self)
                    print("Done Segue")


            }
        }
    }
}
答案
1

You can't perform segue from AppDelegate.

You should do something like this instead of performSegue :

let activityStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = activityStoryboard.instantiateViewController(withIdentifier: "main-activity") 
window?.rootViewController = vc
window?.makeKeyAndVisible()

Replace "main-activity" with the identifier of your viewcontroller you want to reach after setting it up in your storyboard.

How do I segue from AppDelegate after auth from googleSignIn?
查看原网页