【发布时间】:2018-12-05 02:34:37
【问题描述】:
我正在使用 Firebase 和 GoogleSignIn 将用户注册到我的 iOS 应用。我已经按照说明在 AppDelegate.swift 文件中编写了所有代码。登录成功后,我想把用户带到另一个ViewController。我当前的代码是;
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if (error) != nil {
return
}
print("User signed into Google")
guard let authentication = user.authentication else { return }
let credential = FIRGoogleAuthProvider.credential(withIDToken: authentication.idToken,
accessToken: authentication.accessToken)
FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
print("User Signed In to Firebase")
self.databaseRef = FIRDatabase.database().reference()
self.databaseRef.child("Google User Profiles").child(user!.uid).observeSingleEvent(of: .value, with: { (snapshot) in
let snapshot = snapshot.value as? NSDictionary
if(snapshot == nil)
{
self.databaseRef.child("Google User Profiles").child(user!.uid).child("name").setValue(user?.displayName)
self.databaseRef.child("Google User Profiles").child(user!.uid).child("email").setValue(user?.email)
}
})
})
}
【问题讨论】:
-
您在哪个视图控制器中有 google 登录按钮?
-
LoginViewController
-
该链接上没有任何内容提及segues。
-
使用 NSNotificationCenter 将数据从 appdelegate 传递到 loginview 控制器。然后从 loginviewcontroller 执行 segue 到另一个 viewcontroller
标签: swift xcode firebase google-signin