Create push notification when value in firebase da

2019-07-10 10:58发布

问题:

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...

回答1:

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.