@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