我正在尝试使用 Xcode 版本 10.2.1 和 Firebase 为 iOS 应用创建“更新电子邮件”屏幕。使用 Firebase 更新电子邮件的所有代码都工作正常,但当我尝试重新验证用户身份时,出现以下错误:
Cannot convert value of type '(_) -> ()' to expected argument type 'AuthDataResultCallback?' (aka 'Optional<(Optional, Optional) -> ()>')
哦,我正在使用电子邮件凭据来验证用户。
我在这里搜索了多个线程,并浏览了 Firebase 文档,但似乎无法找出导致此错误的原因。
这是我的代码,我从 Firebase Documentation 中提取。 ,以及this thread :
let user = Auth.auth().currentUser
var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")
user?.reauthenticate(with: credential) { error in
if let error = error {
// error handled here
} else {
// success
}
}
错误显示在“user?.reauthenticate(with: credential) { error in ”行上。
有人知道是什么原因造成的吗?
(如果我遗漏了一些明显的东西,我深表歉意。我对使用 Swift/Xcode 还比较陌生。)
谢谢!!
最佳答案
我认为您缺少结果参数
let user = Auth.auth().currentUser
var credential: AuthCredential = EmailAuthProvider.credential(withEmail: "email", password: "pass")
user?.reauthenticate(with: credential) { result, error in
if let error = error {
// error handled here
} else {
// success
}
}
其中结果是 AuthDataResult其中包含成功登录的结果。
关于swift - 使用 Firebase/Xcode 重新验证用户时出错(用于用户电子邮件更新),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56705191/