我想在用户内部丢失连接时更新用户的状态信息。但是当他失去与Firebase的联系时,我无法触发。
这里有一些触发器:
onWrite(), //which triggers when data is created, destroyed, or changed in the Realtime Database.
onCreate(), //which triggers when new data is created in the Realtime Database.
onUpdate(), //which triggers when data is updated in the Realtime Database.
onDelete(), //which triggers when data is deleted from the Realtime Database.
那么如果失去连接,如何更新用户的状态呢?任何提示都将不胜感激
答案 0 :(得分:4)
这可以帮助您:https://firebase.google.com/docs/reference/js/firebase.database.OnDisconnect
在let say / disconnected / {user}
上创建一个onWrite事件假设您使用Swift进行编码,可以使用以下代码:
dataRef.child("disconnected").onDisconnectUpdateChildValues(["uid" : user.uid])
//ofcourse change dataRef to your reference.
当用户断开连接时 - > Firebase执行onDisconnect - > onWrite事件被触发。
使用Javascript:
ref.onDisconnect().update({onlineState: false,status: "I'm offline."})