无法获取图片网址Firebase

时间:2018-10-07 08:03:33

标签: ios swift firebase url firebase-storage

@IBAction func doneTap(_ sender: Any) {
    let imageName = NSUUID().uuidString
    if let image = uploadImage.image {
        if let uploadData = image.pngData() {
            let imgRef = storageRef.child(auth!.uid).child("\(imageName).png")
            imgRef.putData(uploadData, metadata: nil) { (metadata, error) in
                imgRef.downloadURL(completion: { (url, error) in
                    newPlayground(imageURL: url?.absoluteString)
                })
            }
        }
        self.dismiss(animated: true, completion: nil)
    }
}

func newPlayground(imageURL: String) {
    let newPlayground = Playground(title: titleTF.text!, price: priceTF.text!, location: locationTF.text!, description: descriptionTF.text!, images: "", thumbnail: imageURL, city: cityTF.text!, key: key!)
    newPlayground.save()
}

我不知道为什么函数没有在闭包内部运行并且无法访问downloadURL,但是图像被上传到Firebase Storge

0 个答案:

没有答案