无法存储FireBase数据类型'AuthService'没有成员'setUserInformation'数据类型、成员、amp、Fir

2023-09-03 08:41:51 作者:丟了我就別再來找我。つ。

我发现很难解决将数据存储到Firebase控制台上的问题。我相信代码是正确的,但我似乎找不出错误

类型"AuthService"没有成员"setUserInformation"

希望有人能帮我解决我的问题。非常感谢您的帮助!

Google FireBase的简单介绍和使用

我还附上了该问题的屏幕截图:screenshot of problem

static func signUp(username: String, email: String, password: String, firstname: String, lastname: String, imageData: Data, onSuccess: @escaping () -> Void, onError: @escaping (_ errorMessage: String?) -> Void) {
    Auth.auth().createUser(withEmail: email, password: password) { (authData: AuthDataResult?, error: Error?) in
        if error != nil {
            onError(error?.localizedDescription)
            return
        }
        let uid = authData!.user.uid
        let storageRef = Storage.storage().reference(forURL: Config.STORAGE_ROOF_REF).child("profile_image").child(uid)

        storageRef.putData(imageData, metadata: nil, completion: { (_, error: Error?) in
            if error != nil {
                return
            }
            storageRef.downloadURL(completion: { (url: URL?, error: Error?) in
                if let profileImageUrl = url?.absoluteString {

                    self.setUserInformation(profileImageUrl: profileImageUrl!, username: username, email: email, firstname: firstname, lastname: lastname, uid: uid, onSuccess: onSuccess)
                }

              }

            )}

        )}
    }

推荐答案

您在静态方法(Sign Up)中调用了类方法(setUserInformation),这是不允许的,并且self对象在您调用它时没有创建。

您可以通过向setUserInformation方法添加静态或从注册方法中删除静态来解决此问题。