【问题标题】:Create push notification when value in firebase database change当 Firebase 数据库中的值更改时创建推送通知
【发布时间】:2016-08-30 17:11:59
【问题描述】:

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

{
  "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”
    }
  }
}

假设“回合”的值发生了变化,那么我想要向轮到的玩家发送推送通知。但是当用户关闭应用程序时,如何检查“Turn”的值是否发生变化?

我已经阅读了一些有关 Firebase 云消息传递的信息,但似乎找不到答案...

【问题讨论】:

  • 您将需要设置一个所谓的应用服务器来侦听数据库,检测更改,然后将下游消息发送给离线用户。请参阅最近的blog post about a similar scenario。虽然这篇文章谈到了 Android,但同样的方法也适用于 iOS。

标签: ios database firebase push-notification firebase-cloud-messaging


【解决方案1】:

您可以使用 Cloud Functions 对 Firebase 执行此操作。查看https://firebase.google.com/docs/functions/use-caseshttps://firebase.google.com/docs/functions/database-events 了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-12
    • 2016-10-15
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多