4

I try to use GoogleSignIn in my project, but I have problem when call GIDSignIn.sharedInstance().signIn()

I received warning below:

[Warning] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<SFAuthenticationViewController: 0x7fccba008c00>)

And in "GIDSignInDelegate", always had error "The user canceled the sign-in flow."

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {}

I searched on somewhere but could not got any solutions for this case, thanks for reading, I hope you will help me :((

UPDATE 1: add GIDSignInUIDelegate implementation

extension MyClass: GIDSignInUIDelegate {
    func sign(inWillDispatch signIn: GIDSignIn!, error: Error!) {

        print(#function)
    }

    func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!) {
        print(#function)
        self.present(viewController, animated: true, completion: nil)

    }

    func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) {
        print(#function)
        self.dismiss(animated: true, completion: nil)
    }
}

and I received message below:

[Warning] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<SFAuthenticationViewController: 0x103023800>)

UPDATE 2: Some time alert (in image blow) is shown, then I tap on cancel and it can not shown again Image here

baohung02
  • 91
  • 1
  • 7

2 Answers2

5

if you use GIDSignInButton, replace it with the system's UIButton. It works for me.

regina_fallangi
  • 2,080
  • 2
  • 18
  • 38
Tim Hazhyi
  • 161
  • 1
  • 7
  • This works for Swift 5.3/Xcode 12 in 2020. Is this really the most optimal solution? What if I want to keep the default look and feel of Google Sign In – Mochi Dec 07 '20 at 16:53
1

I also had the same issue. The GIDSignInButton object don't need addTarget in code or linking @IBAction. The GIDSignInButton class already handled that action for us.

Hay Trần
  • 564
  • 4
  • 22