Search code examples
cordovafirebasefirebase-realtime-databasecordova-plugin-fcm

how to send push notification when user posts a new message in firebase?


I am using Ionic and firebase. I store all the post from users in ('/posts'). I came across this plug-in. https://github.com/fechanique/cordova-plugin-fcm. There is this part where it has an option to subscribe to topic.

FCMPlugin.subscribeToTopic('topicExample');

but i think this is not for the database. how can I subscribe to my posts ('/post'). to send push notifications?


Solution

  • It has been a while since I last worked with firebase, but if I remember correctly, you can't directly send push notifications by changing the db. You need firebase functions for that.

    Basically what you have to do is write a firebase function that gets triggered when you write to your /post list. You can then send a notification inside that function.

    The whole process is described here, including code samples: https://aaronczichon.de/2017/03/13/firebase-cloud-functions/