How can I prevent to display FCM notification on Flutter app background?
1,057
from the sender device u have to send data only notification
await http.post(
Uri.parse('https://fcm.googleapis.com/fcm/send'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'key=$serverKey',
},
body: jsonEncode(
<String, dynamic>{
'data': <String, dynamic>{
'id': '2',
'status': 'done'
},
'to': userToken,
"collapse_key": uid,
},
),
);
Author by
saeid
Updated on December 30, 2022Comments
-
saeid over 1 year
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async { print('Handling a background message ${message.messageId}'); }
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
I can display background notifications with these snippet codes. But is there any way to not display some specific notification in the background?
For example I don't want to display notifications with
data = {title = "call"}
-
Ali Izadyar almost 2 yearsfound the solution? I have the same problem
-
-
saeid almost 3 yearsin
_firebaseMessagingBackgroundHandler
function we don't implement anything to display notification, automatically displayed if we pass the empty function to FirebaseMessaging.onBackgroundMessage -
Benyamin Beyzaie over 2 yearsthis method is not related to this topic if you don't write this function at all the notification will appear! so it is not helpful...
-
PeakGen almost 2 yearsData only notifications will not show up in iOS if the device is rebooted. It will show again if the user opens the app.
-
Husen almost 2 years@PeakGen The purpose of data-only notification is not to show up, I tested this approach and it worked on android, I am not sure about IOS.