我使用firebase上传照片,视频和文字。我如何添加简单的按钮来从firebase中删除信息(数据库和存储) Firebase Database Console
static func uploadDataToServer(data: Data, videoUrl: URL? = nil, ratio: CGFloat, caption: String, Location: String, onSuccess: @escaping () -> Void) {
if let videoUrl = videoUrl {
self.uploadVideoToFirebaseStorage(videoUrl: videoUrl, onSuccess: { (videoUrl) in
uploadImageToFirebaseStorage(data: data, onSuccess: { (thumbnailImageUrl) in
sendDataToDatabase(photoUrl: thumbnailImageUrl, videoUrl: videoUrl, ratio: ratio, caption: caption, Location: Location, onSuccess: onSuccess)
})
})
} else {
uploadImageToFirebaseStorage(data: data) { (photoUrl) in
self.sendDataToDatabase(photoUrl: photoUrl, ratio: ratio, caption: caption, Location: Location, onSuccess: onSuccess)
}
}
}
static func uploadImageToFirebaseStorage(data: Data, onSuccess: @escaping (_ imageUrl: String) -> Void) {
let photoIdString = NSUUID().uuidString
let storageRef = Storage.storage().reference(forURL: Config.STORAGE_ROOF_REF).child("posts").child(photoIdString)
storageRef.putData(data, metadata: nil) { (metadata, error) in
if error != nil {
ProgressHUD.showError(error!.localizedDescription)
return
}
if let photoUrl = metadata?.downloadURL()?.absoluteString {
onSuccess(photoUrl)
}
}
}
答案 0 :(得分:0)
@IBAction func DeletePost(_ sender: Any) {
let alert = UIAlertController(title: "Delete Post", message: "Are You Sure ?", preferredStyle: .alert);
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil));
let okAction = UIAlertAction(title: "Delete", style: .default) {(action) in
//.............Delete From Firebase Code
};
alert.addAction(okAction);
self.present(alert, animated: true, completion: nil);
}