我已经遵循了here官方文档中提供的所有步骤来实现iOS的谷歌登录。
所以我有谷歌登录按钮的LoginVC,当该按钮被点击时,它将显示由谷歌创建的登录页。下面是google登录按钮的IB操作
@IBAction func googleButtonDidPressed(_ sender: Any) {
GIDSignIn.sharedInstance().signIn()
}用户登录成功后,它将从谷歌登录页面返回到LoginVC。在用户成功登录后,我想在LoginVC中执行另一个操作。
问题是,当用户成功登录时,会在App Delegate中触发下面的方法。但是我需要LoginVC格式的GIDGooleUser数据,而不是appdelegate格式的
extension AppDelegate : GIDSignInDelegate {
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
// this method called after the user login successfully
// i need user: GIDGoogleUser in my LoginVC
}
}我需要该GIDGooleUser来获取credential,然后该credential将用于登录以获取AuthDataResult和FirebaseUser
那么如何在登录成功时通知我的LoginVC并将GIDGooleUser带到我的LoginVC中呢?
发布于 2020-06-03 04:49:47
示例代码: func sign(_ signIn: GIDSignIn!,didSignInFor user: GIDGoogleUser!,withError error: Error!) { if let error = error { print("(error.localizedDescription)") NotificationCenter.default.post(name: NSNotification.Name(rawValue: googleSignInNotification),object: nil,userInfo:"result“:false) } else { let userId:String = user.userID let idToken:String = user.authentication.idToken let fullName:String = user.profile.name let givenName:String = user.profile.givenName let familyName:String = user.profile.familyName let email:String = user.profile.email let imageUrl:String=user。profile.imageURL(withDimension:100).absoluteString让userDetailsDictionary: String:String = "FirstName":givenName,"LastName":familyName,“性别”:"",“道布”:"","GoogleID":userId,"FacebookID":"","Email":email,"ProfilePicUrl“:imageUrl
NotificationCenter.default.post(名称: NSNotification.Name(rawValue: googleSignInNotification),对象:空,userInfo:"result“:true) }
}https://stackoverflow.com/questions/61887067
复制相似问题