0
我需要使用Google-SignIn SDK對其進行身份驗證, 當我在類UIViewcontroller類中使用它時,它工作成功。 但我需要在一個單獨的類中實現signIn方法我應該怎麼做才能成功工作? 我的GoogleLogin類看起來像谷歌登錄不在非UIViewController中起作用
import Foundation
import GoogleSignIn
class GoogleLogin:NSObject, LoginAuthProtocol, GIDSignInDelegate, GIDSignInUIDelegate{
weak var googleView: UIViewController!
init(view: UIViewController) {
super.init()
googleView = view
GIDSignIn.sharedInstance().clientID = "1017499022947-4d73nf64.apps.googleusercontent.com"
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().delegate = self
}
func login() {
GIDSignIn.sharedInstance().signIn()
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if error != nil{
print("*****error \(error.localizedDescription) ******")
return
}
print(user.profile.email)
}
func sign(inWillDispatch signIn: GIDSignIn!, error: Error!) {
}
func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!) {
googleView.present(viewController, animated: true, completion: nil)
}
func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) {
googleView.dismiss(animated: true, completion: nil)
}
}
當我要開始登錄我叫login()方法從我的根的viewController和路徑自身作爲參數
GoogleLogin(view: self).login()
但電話後沒有發生!