“StorageReference”类型的值没有成员“put”

时间:2017-05-21 20:58:00

标签: swift firebase firebase-storage

我更新到firebase存储4.0,现在我收到此错误,说storageRef没有成员“put”。它曾在旧版本的Firebase中运行。

    if let selectedImage = selectedImageFromPicker {
        profilePic.image = selectedImage
        if let uploadData = UIImagePNGRepresentation(selectedImage) {
            let storageRef = Storage.storage().reference().child("profile pictures").child("\(Auth.auth().currentUser?.uid).png")
            storageRef.put/*error here*/(uploadData, metadata: nil, completion: {
                (metadata, error) in
                if error != nil {
                    print(error!)
                    return
                }
                print(metadata!)

                if let profilePictureURL = metadata?.downloadURL()?.absoluteString {

                    let ref = FIRDatabase.database().reference()
                    let usersreference = ref.child("users").child(Auth.auth().currentUser?.uid).child("data")
                    usersreference.updateChildValues(["profile picture": profilePictureURL])
                }
            })
        }
    }

1 个答案:

答案 0 :(得分:14)

根据Firebase的migration support,它已更改为putData(_:metadata:completion:)