問題描述
我正在使用 firebase 創(chuàng)建一個 Ionic 2 應(yīng)用程序,我需要一種方法來在應(yīng)用程序關(guān)閉時(即在前臺、后臺和被終止)收聽數(shù)據(jù)庫更改(特別是在 child_add 上)
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)
基本上,我想使用 WebRTC 在應(yīng)用程序中撥打電話,例如 whatsapp,我正在關(guān)注這篇文章 - https://websitebeaver.com/insanely-simple-webrtc-video-chat-using-firebase-with-codepen-demo
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
但是,唯一讓我感到困惑的是,當應(yīng)用程序關(guān)閉時它會如何工作.誰能幫我理解一下?
However, the only thing that puzzles me is how it will work when the app is closed. Can anyone please help me understand?
謝謝!
推薦答案
使用 Firebase 客戶端 SDK 來主動監(jiān)聽數(shù)據(jù)庫更改是不可能的,就像在應(yīng)用代碼運行時一樣.
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.
如果您希望您的應(yīng)用接收有關(guān)數(shù)據(jù)庫更改的信息,您可以改用 Firebase Cloud Messaging 向您的應(yīng)用發(fā)送通知,其中包含有關(guān)更改的信息的小負載.當您的應(yīng)用收到通知時,它可以決定要做什么.網(wǎng)絡(luò)支持有一些限制,所以請務(wù)必閱讀那個.
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.
還可以查看 Cloud Functions for Firebase,以便更輕松地編寫一些服務(wù)器端可以觸發(fā)以響應(yīng)數(shù)據(jù)庫更改并在這些更改發(fā)生時發(fā)送通知的代碼.
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.
這篇關(guān)于關(guān)閉應(yīng)用程序時收聽 Firebase 數(shù)據(jù)庫更改的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!