Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

firebase - Flutter notifications

I'm using firebase as database. Flutter responds when any changes are made in cloud while using app, but will is respond the changes even when the app is in background or killed?

Second: is it possible to create notifications within the flutter app without using Firebase notification feature? Like a new document is added in database and app is suppose to create notification using some specific lib from pubdev.

question from:https://stackoverflow.com/questions/65865718/flutter-notifications

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When the user is not actively using the app, the OS (Android or iOS) allows a very limited amount of network activity from that app. For this reason you'll typically stop receiving updates from Firebase once the app is backgrounded, and you won't receive any updates as soon as it's killed.

If you want to show updates to the user when they're not using the app, that typically takes using Firebase Cloud Messaging. With this scenario you:

  1. Set up custom server-side code that listens to the database. This code can run on your own server, but also for example on Cloud Functions.
  2. When this code detects a change to the data, it sends a message to the relevant user(s) through Firebase Cloud Messaging.
  3. This requires that the app registers itself either in your database (with its FCM token) or for a certain FCM topic to receive updates about.

For more on this, see the Firebase documentation on Cloud Messaging, Cloud Functions, my answer here and the FlutterFire docs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...