Listen to firebase database changes when app is closed

这一生的挚爱 提交于 2020-06-23 11:14:52

问题


I am creating an Ionic 2 app with firebase and I need a way to listen to database changes (specifically on child_added) when the app is closed (I.e. in foreground,background and killed)

Basically, I want to use WebRTC to make calls within the app like whatsapp and I am following this post - https://websitebeaver.com/insanely-simple-webrtc-video-chat-using-firebase-with-codepen-demo

However, the only thing that puzzles me is how it will work when the app is closed. Can anyone please help me understand?

Thanks!


回答1:


It's not possible to actively listen to database changes using the Firebase client SDK in exactly the same way that you can when your app's code is running.

If you want your app to receive information about changes to your database, you can instead use Firebase Cloud Messaging to send your app a notification with a small payload that contains information about the change. When your app receives the notification, it can then make a decision about what to do. There are some limitations with web support, so be sure to read about that.

Also look into Cloud Functions for Firebase to make it easier to write some server side code that can trigger in response to a database change and send a notification when those changes happen.



来源:https://stackoverflow.com/questions/48426240/listen-to-firebase-database-changes-when-app-is-closed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!