-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Discussed in #6113
Originally posted by Minituff May 11, 2021
Background
I am trying to create a chat app which delivers reliable notifications that includes action buttons such as Mark as Read
and Reply
which creates an input field.
Unfortunately the firebase_messaging
plugin does not support advanced options like Action/Input buttons. So, to do this in Flutter, I am using a great package called AwesomeNotifications which allows for all these advanced features. For anyone unfamiliar, it is like a more advanced version of the Local Notifications plugin.
Using this plugin, I am able to handle the FirebaseMessaging.onBackgroundMessage(_fcmBackgroundHandler);
callback from firebase_messaging
and generate the notification with all the properties and actions that I like.
The Problem
If the notification includes the notification
property then firebase_messaging
will automatically display the notification and AwesomeNotifications will then display its notification--resulting in duplicate notifications.
However, removing the notification
property turns it into a data-only
notification which, according to the FlutterFire docs are low-priority`
As mentioned above, data only messages are classed as "low priority". Devices can throttle and ignore these messages if your application is in the background, terminated, or a variety of other conditions such as low battery or currently high CPU usage.
You should not rely on data only messages to be delivered, they should only be used to support your applications non-critical functionality, e.g. pre-fetching data so the next time the user opens your app the data is ready to be displayed and if the message never gets delivered then your app still functions and fetches data on open.
To help improve delivery, you can bump the priority of messages. Note; this does still not guarantee delivery.
I have also tested this with my own IOS and Android devices and I would not receive data-only messages unless the app was in the foreground or the last used app on IOS. Notifications would not come through if I was using another app, or it was swiped away from recents.
For a chat application, getting reliable messages is a priority and therefore I need to use the notification
property to ensure delivery of my notifications. The issues:
- I cannot use a plugin like AwesomeNotifications or Local Notifications to create advanced functioning notifications because it will create duplicate notifications as long as the
notification
property is set. However, thenotification
property is required for reliable notifications. - The
firebase_messaging
plugin does not support advanced features such as Action/Input buttons.
A greater explanation of (number 1):
firebase_messaging
automatically intercepts notifications and displays them and I don't think there is a way to disable that. Per the docs below:
Messages can be handled via the onBackgroundMessage handler. When received, an isolate is spawned (Android only, iOS/macOS does not require a separate isolate) allowing you to handle messages even when your application is not running.
and further
If your message is a notification one (includes a notification property), the Firebase SDKs will intercept this and display a visible notification to your users (assuming you have requested permission & the user has notifications enabled). Once displayed, the background handler will be executed (if provided).
The Feature Request
I would like to be able to disable the firebase_messaging
automatic notification display while still having the onBackgroundMessage
callback fire. This way I can send reliable notifications (with the notification
property) and have them be displayed by the more advanced flutter tools.
If this is not possible, then I would love to see ActionButtons and Input fields come to the firebase_messaging
plugin.
Additional Infromation
I created another issue here https://github.com/rafaelsetragni/awesome_notifications/issues/165