@IBAction func GoogleLoginDidTapped(_ sender: Any) {
print("Google login completed")
try? GIDSignIn.sharedInstance().signIn()
try? GIDSignIn.sharedInstance().uiDelegate = self
try? GIDSignIn.sharedInstance().delegate = self
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
try? auth(authentication: user.authentication)
}
func auth(authentication: GIDAuthentication)
{
let credential = FIRGoogleAuthProvider.credential(withIDToken: authentication.idToken , accessToken: authentication.accessToken)
FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in
if error != nil{
print(error?.localizedDescription)
}
else
{
print(user?.email)
print(user?.displayName)
x = true
name = (user?.displayName)!
self.movespecial()
}
})
}
我可以登录,但是当谷歌窗口打开时,如果我点击完成,应用程序崩溃了。有人能帮帮我吗?提前谢谢。
我已经在这个应用程序上工作了一段时间,这是最后一步。 我得到的错误是
fatal error: unexpectedly found nil while unwrapping an Optional value
答案 0 :(得分:0)
我找到了解决方案
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if error == nil
{
auth(authentication: user.authentication)
}
else
{
print(error.localizedDescription)
}
}