GIDSignIn.sharedInstance()。signInSilently()无响应

时间:2018-08-18 23:24:36

标签: firebase-authentication google-cloud-firestore google-signin

我在我的iOS应用中向其他VC添加了一些新功能,但突然间Google静音登录对我不起作用。以下是我的代码。基本上,在执行“ GIDSignIn.sharedInstance()。signInSilently()”之后,没有任何响应。执行只是直接执行func“ sign”。

//Mandate SignIn when Track buttion is pressed
@IBAction func trackButtonPressed(_ sender: UIButton) {
    //Code added for Google SignIn
    GIDSignIn.sharedInstance().uiDelegate = self
    GIDSignIn.sharedInstance().delegate = self
    let firebaseAuth = Auth.auth()

    if (GIDSignIn.sharedInstance().hasAuthInKeychain()) {
        print("ViewController: User is signed in or has previous authentication parameters saved in keychain")
        // SignIn silently only if user is not already signed in
        if(GIDSignIn.sharedInstance().currentUser == nil) {
            print("ViewController: Entered signInSilently block, executing silent signin !!")
            GIDSignIn.sharedInstance().signInSilently()
            print("ViewController: Done. Executed signInSilently !!")
            DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2), execute: {
                self.handle = Auth.auth().addStateDidChangeListener() { (auth, user) in
                    if user != nil {
                        print("ViewController: USER SIGNED IN SILENTLY !!")
                        self.userSignedIn = true
                        print("ViewController: Since user silently signed in segue to TrackProgressVC")
                        self.performSegue(withIdentifier: "SegueToTrackProgressVC", sender: self)
                    } else {
                        print("ViewController: User NOT SignedIn even after executing signInSilently")
                    }
                }
            })
        } else {
            print("ViewController: User is already signed in, Segue to TrackProgressVC")
            self.performSegue(withIdentifier: "SegueToTrackProgressVC", sender: self)
        }
    } else if (firebaseAuth.currentUser != nil) {
        self.userSignedIn = true
        print("ViewController: Since user is already signed in segue to TrackProgressVC")
        self.performSegue(withIdentifier: "SegueToTrackProgressVC", sender: self)
    } else {
        print("ViewController: User doesn't have previous authentication parameters saved in keychain")
        // which means user has to singin manually
        print("ViewController: Show SignIn View Controller")
        self.performSegue(withIdentifier: "ToSignUpVC", sender: self)
    }
}

0 个答案:

没有答案