swift - FIREBASE 4 类型 'StorageReference' 的值没有成员 'put'

标签 swift firebase

我编写的第一个应用程序有问题。我在 YouTube 上观看了关于如何让用户注册 Firebase 并选择个人资料照片的教程。在视频中一切正常,但在我的项目中它给了我以下错误:

Value of type 'StorageReference' has no member 'put'

我已经看过关于这个主题的帖子,但我不喜欢那里给出的这个答案 (Value of type 'StorageReference' has no member 'put')。

这是我的完整代码:

let uploadTask = imageRef.put(data!, metadata: nil, completition: { (metadata, error) in

                    if err != nil{
                        print(err!.localizedDescription)
                    }

                    imageRef.downloadURL(completion: { (url, er) in
                        if er != nil{
                            print(er!.localizedDescription)
                        }

                        if let url = url {

                            let userInfo: [String: Any] = ["uid" : user.uid,
                                                           "full name" : self.nameField.text!,
                                                           "urlToImage" : url.absoluteString]

                            self.ref.child("users").child(user.uid).setValue(userInfo)


                            let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController
                            (withIdentifier: "userVC")

                            self.present(vc, animated: true, completion: nil)
                        }

                    })

                })

错误出现在第一行。

最佳答案

根据documentation以及您链接的问题,最新版本的 Firebase 使用 putData,而不是 put

let uploadTask = imageRef.putData(data!, metadata: nil) { (metadata, error) in

  // your code here

})

关于swift - FIREBASE 4 类型 'StorageReference' 的值没有成员 'put',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48772931/

相关文章:

ios - Xcode 7 Swift 2 无法实例化通用 UITableViewController 的 UIViewController 子类

java - 如何在电话身份验证期间检查用户是否已存在于 firebase 中

java - 数据库中的值每天加一

swift 2错误: Solve "Type of expression is ambiguous without more context"

ios - Realm数据库在IOS应用中的难点

swift - 使用字符串数组用 UIButtons 填充 UIStackView

Swift 协议(protocol)可通过只读属性设置属性

java - Firebase - 如何确保已通过身份验证的用户不会再次进行身份验证?

ios - iOS FirebaseAnalytics Pod 中的非模块 header

Firebase:协作应用程序的安全规则