Swift Google登录代理未被调用

Swift Google登录代理未被调用,swift,google-login,Swift,Google Login,我已经将我的google登录逻辑移到了一个单独的类中,问题是,由于这样做,“sign”委托函数不会被调用,我也不知道为什么 import Foundation import Firebase import GoogleSignIn class Google: NSObject, GIDSignInDelegate { func login(vc: UIView){ GIDSignIn.sharedInstance().delegate = self

我已经将我的google登录逻辑移到了一个单独的类中,问题是,由于这样做,“sign”委托函数不会被调用,我也不知道为什么

import Foundation
import Firebase
import GoogleSignIn

class Google: NSObject,  GIDSignInDelegate {



    func login(vc: UIView){

       GIDSignIn.sharedInstance().delegate = self
       GIDSignIn.sharedInstance().presentingViewController = UIApplication.shared.keyWindow!.rootViewController!
       GIDSignIn.sharedInstance().signIn()


    }


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

    print("Google Sign In didSignInForUser")
          if let error = error {
            print(error.localizedDescription)
            return
          }

          guard let authentication = user.authentication else { return }
          let credential = GoogleAuthProvider.credential(withIDToken: (authentication.idToken)!, accessToken: (authentication.accessToken)!)
      // When user is signed in
          Auth.auth().signIn(with: credential, completion: { (user, error) in
            if let error = error {
              print("Login error: \(error.localizedDescription)")
              return
            }
          })
        }
}
从子视图调用google类:

import Foundation
import UIKit



class NewToMoonBar: UIView  {


    @IBOutlet var googleLogin: UIButton!
    @IBOutlet var loginButton: UIButton!

    static func show(vc: UIView) -> UIView {
        let myCustomView = Bundle.main.loadNibNamed("NewToMoonBar", owner: self, options: nil)?.first as? NewToMoonBar
        myCustomView!.frame.origin.x = 0
        myCustomView!.frame.origin.y = 0
        myCustomView?.frame.size.width = vc.frame.width
        myCustomView?.frame.size.height = vc.frame.height
        myCustomView!.tag = 100
        return myCustomView!
    }

    @IBAction func loginButton(_ sender: Any) {

        Facebook().login(vc: self)
    }

    @IBAction func googleLogin(_ sender: Any) {


        Google().login(vc: self)
    }


}

您已经在这里创建了局部变量

 Facebook().login(vc: self)
 Google().login(vc: self)
因此,取消分配会发生,并导致委托不会被触发,您需要使它们成为实例变量

let f =  Facebook() 
let g =  Google() 

对于要保留的学员

如何使用
Google
class?