在Firebase数据库更改值时创建推送通知 [英] Create push notification when value in firebase database change

查看:147
本文介绍了在Firebase数据库更改值时创建推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的firebase数据库中的值发生更改时向用户发送推送通知。这是我的数据库

$ $ $
战斗{
00000111-062B3333-4046-4FB4 -A37-C2B05853E497:{
BattleProgress:,
Player1:lzsPuNwHbIZI1J8k40FspYRV4XQ2,
Player2:tHNBif9csWNCOuftAGLAqvLWNUw1,
Score 0-0,
转:1
}
},
users:{
lzsPuNwHbIZI1J8k40FspYRV4XQ2:{
Coins :1,
Dollars:0,
FBID:ID,
GamesLost:0,
GamesWon:0,
name:Name
},
tHNBif9csWNCOuftAGLAqvLWNUw1:{
硬币:0,
美元:0,
FBID: B,B,B,B

可以说,Turn的值发生了变化,然后我想要发送一个推送通知给这个玩家是谁呢?但是,如何在用户关闭应用程序时检查Turn的值是否发生了变化?我已经阅读了一些关于Firebase Cloud Messaging的内容,但是看起来似乎不能找到答案...

解决方案

您可以使用Cloud Functions在Firebase中执行此操作。查看 https://firebase.google.com/docs/functions/use-cases https://firebase.google.com/docs/functions/database-事件获取更多信息。


I want to send a push notification to the user when a value in my firebase database change. this is my database

{
  "Battles" : {
    "00000111-062B3333-4046-4FB4-AA37-C2B05853E497" : {
      "BattleProgress" : "",
      "Player1" : "lzsPuNwHbIZI1J8k40FspYRV4XQ2",
      "Player2" : "tHNBif9csWNCOuftAGLAqvLWNUw1",
      "Score" : "0-0",
      "Turn" : 1
    }
  },
  "users" : {
    "lzsPuNwHbIZI1J8k40FspYRV4XQ2" : {
      "Coins" : 1,
      "Dollars" : 0,
      "FBID" : "ID",
      "GamesLost" : 0,
      "GamesWon" : 0,
      "name" : "Name"
    },
    "tHNBif9csWNCOuftAGLAqvLWNUw1" : {
      "Coins" : 0,
      "Dollars" : 0,
      "FBID" : "ID",
      "GamesLost" : 0,
      "GamesWon" : 0,
      "name" : "Name"
    }
  }
}

So lets say, the value of "Turn" changes, then I want a push notification sent out to the player whos turn it is. But how can I check if the value of "Turn" changes when the user shuts down the app?

I've read a bit about Firebase Cloud Messaging, but cant seem to find the answar...

解决方案

You can do this with Firebase using Cloud Functions. Check out https://firebase.google.com/docs/functions/use-cases and https://firebase.google.com/docs/functions/database-events for more information.

这篇关于在Firebase数据库更改值时创建推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆