quickstart-js icon indicating copy to clipboard operation
quickstart-js copied to clipboard

How can I prevent to show notifications on background?

Open damandeepsinghbhatia opened this issue 4 years ago • 4 comments

I have tried messaging.setBackgroundMessageHandler(function(payload){

}); unfortunately this is not working. I am using 8.2.9 version importScripts('https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js'); importScripts('https://www.gstatic.com/firebasejs/8.2.9/firebase-messaging.js');

damandeepsinghbhatia avatar Mar 30 '21 15:03 damandeepsinghbhatia

I have the same question. It appears that the setBackgroundMessageHandler event handler has been deprecated & no longer works.

The onBackgroundMessage handler only allows you to customize a notification, but it doesn't provide a means to completely prevent all notifications from showing; FCM will still show a default notification, even if this event handler is defined as a dummy function.

How does one go about implementing logic to conditionally display a background notification???

EDIT: nevermind, I found a work-around, which is to setup my push notification as a data-only message (i.e., don't include a 'notification' field in the push request), and handle the creation of the notification object within my 'onBackgroundMessage' handler...

csurf avatar Apr 22 '21 03:04 csurf

@csurf brilliant!!!

Chris-LuYi avatar May 11 '21 05:05 Chris-LuYi

yes but ios not worked if field notification exclude

UncleWeb1992 avatar Jun 26 '23 05:06 UncleWeb1992

can you teach me how to do that? I dun get how to remove notification field works

Chooyinkeat avatar Oct 05 '23 13:10 Chooyinkeat