当用户在firebase中发布新消息时如何发送推送通知?

时间:2017-07-06 03:30:03

标签: cordova firebase firebase-realtime-database cordova-plugin-fcm

我正在使用Ionic和firebase。我将用户的所有帖子存储在(' / posts')中。我遇到了这个插件。 https://github.com/fechanique/cordova-plugin-fcm。这部分可以选择订阅主题。

FCMPlugin.subscribeToTopic('topicExample');

但我认为这不适用于数据库。我如何订阅我的帖子(' / post')。发送推送通知?

1 个答案:

答案 0 :(得分:2)

自从我上次使用firebase以来已经有一段时间了,但如果我没记错的话,你不能通过更改数据库直接发送推送通知。你需要firebase功能。

基本上你要做的就是编写一个firebase函数,当你写入/post列表时会触发该函数。然后,您可以在该功能内发送通知。

此处描述了整个过程,包括代码示例: https://aaronczichon.de/2017/03/13/firebase-cloud-functions/