我正在尝试链接Facebook和Google。因此,情况是这样的:
我已经通过Google身份验证。所以,现在我登录Facebook,使用的电子邮件ID与Google之前使用的相同。因此,我收到了具有不同凭证的帐户存在错误。而且,我做到了:
func fetchUserInfo()
{
Auth.auth().signInAndRetrieveData(with:FacebookAuthProvider.credential(withAccessToken: (FBSDKAccessToken.current().tokenString)!), completion: { (result, error) in
if let error = AuthErrorCode.init(rawValue: error!._code)
{
switch error
{
case .accountExistsWithDifferentCredential :
let credential = FacebookAuthProvider.credential(withAccessToken: (FBSDKAccessToken.current()?.tokenString)!)
Auth.auth().currentUser?.linkAndRetrieveData(with: credential, completion: { (result, error) in
if let error = error
{
print("Unable to link Facebook Account", error.localizedDescription)
}
else
{
NavigationHelper.shared.moveToHome(fromVC: self)
}
})
default: break
}
}
else
{
GeneralHelper.shared.keepLoggedIn()
if let currentUser = Auth.auth().currentUser
{
print(currentUser.email!)
}
NavigationHelper.shared.moveToHome(fromVC: self)
}
})
}
此处Firebase文档说,我们只需要链接currentUser
并检索数据。但是,我面临的问题是currentUser
始终为零。那么,如何获得当前用户?我已经在这个月前尝试过了,然后就可以链接Facebook,Google和Email。是吗,我需要signInAndRetrieve
来自Google的数据才能获得currentUser
?