【发布时间】:2019-08-29 06:55:59
【问题描述】:
当任何用户想从应用程序更新他/她的密码时,我想更新同一个 FCM 用户的密码,为此我尝试了以下官方文档中定义的代码。
这是我的代码
func authenticateAndUpdateFCMUserPassword(strNewPassword: String) {
let user = Auth.auth().currentUser
var credential: AuthCredential
// Prompt the user to re-provide their sign-in credentials
user?.reauthenticate(with: credential) { error in
if let error = error {
// An error happened.
} else {
// User re-authenticated.
}
}
Auth.auth().currentUser?.updatePassword(to: strNewPassword) { (error) in
if error != nil {
print("Error occur while updating password")
}
else {
print("Password Updated Successfully")
}
}
}
但在上面的代码中,我在user?.reauthenticate 行遇到以下错误
无法将类型 '(_) -> ()' 的值转换为预期的参数类型 'AuthDataResultCallback?' (又名'可选 ()>')
所以我用下面的代码重新写了
user?.reauthenticate(with: credential, completion: { (dataResult, errorr) in
if errorr != nil {
// An error happened.
} else {
// User re-authenticated.
}
})
但是在上面的代码中我遇到了下面的错误
在初始化之前使用的变量“凭据”
凭据只定义一次,在此之前从未使用过
谁能告诉我我做错了什么?
【问题讨论】:
标签: ios swift firebase firebase-authentication