如果用户在Ionic中强制关闭应用程序,如何将其从Firebase阵列中删除

时间:2018-11-24 17:26:20

标签: javascript firebase ionic3

所以我到处检查,似乎无法找到一种方法来做到这一点。我正在创建一个聊天功能,并且有一个菜单显示当前在某个聊天页面上的所有用户。我在Firebase中有一个数组输入了聊天的用户。

如果应用仍在后台运行,我知道如何删除用户。我不知道当用户强行关闭应用程序时如何从阵列中删除用户。

这是用于在用户回家并且应用仍在后台运行时删除用户的代码:

//Remove user from online list if app is in background
document.addEventListener('pause', () => {
  this.chatDB.update({
    users: firebase.firestore.FieldValue.arrayRemove(firebase.auth().currentUser.toJSON())
  });
})
//Add user if re enters the app from when it was in the background
document.addEventListener('resume', () => {
  this.chatDB.update({
    users: firebase.firestore.FieldValue.arrayUnion(firebase.auth().currentUser.toJSON())
  });
})

但是当我尝试强制关闭应用程序时,这些功能无法运行

0 个答案:

没有答案