【问题标题】:Cannot convert value of type '(User?, Error?) -> ()' to expected argument type 'AuthDataResultCallback?'无法将类型“(用户?,错误?)->()”的值转换为预期的参数类型“AuthDataResultCallback?”
【发布时间】:2018-05-27 07:47:20
【问题描述】:

当我更新 firebase pod 时出现此错误:

无法将类型“(用户?,错误?)->()”的值转换为预期的参数类型“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 吗?

标签: swift firebase


【解决方案1】:

只写没有类型定义的闭包。

更新代码:

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

【讨论】:

  • 已修复但出现新错误>“AuthDataResult”类型的值没有成员“uid”
  • @felon 我认为this 的问题会对你有所帮助
  • @felon 如果我的回答帮助您解决了错误 - 请接受并投票
【解决方案2】:

尝试以下方法:

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)
        })
    })
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-05
    • 2023-04-04
    • 2016-05-03
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多