evollu / react-native-fcm

react native module for firebase cloud messaging and local notification
MIT License
1.73k stars 682 forks source link

show_in_foreground is false but banner still showing when app is in foreground #908

Closed vvusts closed 6 years ago

vvusts commented 6 years ago

"react": "16.0.0-alpha.12", "react-native": "0.52.1", "react-native-fcm": "^14.1.3"

I don't want to show banner when I push notifications from server. I thought this show_in_foreground would prevent it but it's still showing when app is in foreground.

For local notification I made:

case NotificationType.WillPresent:
                notif.finish(WillPresentNotificationResult.None)

But for remote notifications this is not enough. How to stop showing banner when in foreground? My use case is to show banner if app is not in foreground and do other things when it is.

This is how I send notification:

{
"to":"xxxxxxxxxxx",
"notification":
{
  "title":"Title", "body":"Description", "sound":"default"},
  "data":{"targetScreen":"details", "show_in_foreground": false},
  "priority":10
}
sfm2222 commented 6 years ago

Sorry I don't know why it is showing but can you tell How you are able to show the notification when app was open.

Can you share more code of listener and other parts. I'm trying to do that. Thanks. https://github.com/evollu/react-native-fcm/issues/909

evollu commented 6 years ago

@vvusts if you don't want notification to be shown, use data message?

vvusts commented 6 years ago

@evollu not like that. Server should send notification but if app is in foreground I should show alert instead of banner. Basically if app is in foreground alert and if app is closed or in background banner. Everything work fine there must be some trick to detect when notification arrived.

@sfm2222 what code part you want to see. I did everything like in doc and it worked.

evollu commented 6 years ago

try

{
"to":"xxxxxxxxxxx",
"notification":
{
  "title":"Title", "body":"Description", "sound":"default"
},
"data":{"targetScreen":"details", "show_in_foreground": false},
  "priority":10
}
vvusts commented 6 years ago

@evollu I did that and notification is not showing when app is in foreground. I need to make this also on android. EDIT: It actually work :) sorry