[英]Swift- Response Handler on Firebase Write Operations
我正在遵循新的Firebase文檔來執行寫操作。 但是,我看不到任何允許我在寫操作中偵聽Firebase響應的代碼。
這是我的代碼:
ref.child("Canciones").childByAutoId().setValue(["Categoria":song.categoria, "Titulo":song.titulo, "Autor":song.autor, "Votos":song.votos])
我正在尋找可以為我返回響應的信息,以通知用戶該請求已成功執行。 例如:
ref.child("Canciones").childByAutoId().setValue(["Categoria":song.categoria, "Titulo":song.titulo, "Autor":song.autor, "Votos":song.votos]) { response in
if error != nil {
//..etc..//
}
謝謝!
let message = ["name": "puf", "text": "Hello from iOS"]
ref!.childByAutoId().setValue(message) { (error) in
print("Error while writing message \(error)")
}
從文檔中作為替代答案
func setValue(_ value: Any?, withCompletionBlock block: @escaping (Error?, FIRDatabaseReference) -> Void)
像這樣使用
let ref = rootRef.child("Canciones").childByAutoId()
ref.setValue("Hello, World", withCompletionBlock: { (error, ref) in
if error == nil {
print("success")
} else {
print("failure")
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.