无法将 '(User?, Error?) -> ()' 类型的值转换为预期的参数类型 'AuthDataResultCallback?'



当我更新Firebase pods时收到此错误:

无法将类型为"(用户?,错误?("(->(("的值转换为预期的参数类型"AuthDataResultCallback?"(又名"可选<(可选,可选(->((>"(

static func signUp(username: String, email: String, User: String, Phone: String ,password: String, imageData: Data, onSuccess: @escaping () -> Void, onError:  @escaping (_ errorMessage: String?) -> Void) {
Auth.auth().createUser(withEmail: email, password: password, completion: { (user: User?, error: Error?) in
if error != nil {
onError(error!.localizedDescription)
return
}

我该如何解决这个问题?

只需编写闭包而不定义类型。

更新的代码:

Auth.auth().createUser(withEmail: email, password: password, completion: { user, error in
...
}

尝试以下操作:

static func signUp(username: String, email: String, User: String, Phone: String ,password: String, imageData: Data, onSuccess: @escaping () -> Void, onError:  @escaping (_ errorMessage: String?) -> Void) {
Auth.auth().createUser(withEmail: email, password: password, completion: { user, error in
if error != nil {
onError(error!.localizedDescription)
return
}
let uid = user?.uid
let storageRef = Storage.storage().reference(forURL: Config.STORAGE_ROOF_REF).child("profile_image").child(uid!)
storageRef.putData(imageData, metadata: nil, completion: { (metadata, error) in
if error != nil {
return
}
let profileImageUrl = metadata?.downloadURL()?.absoluteString
self.setUserInfomation(profileImageUrl: profileImageUrl!, username: username, Phone: Phone,email: email,User:User, uid: uid!, onSuccess: onSuccess)
})
})
}

最新更新