Skip to content

onNotification not triggered when app is in background - but heads up notification works fine #1222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vvusts opened this issue Jun 17, 2018 · 24 comments

Comments

@vvusts
Copy link

vvusts commented Jun 17, 2018

I have issue on both platforms.
I am using react native 52.1 and latest version of RN firebase.
I can show heads up notification on both OS (push or scheduled notifications) when app is in background, killed and when app is in foreground onNotification is triggered so I make some other action in that case (like show alert and not heads up notification).
My problem is I need to increase app icon badge when get notification.
But I can't do that as onNotification is not triggered when app is in background.
So I see notification banner but callback itself was not called.
My payload:

{
	"to": "tttToken",
	"notification" : {
      "body" : "test",
      "title" : "test",
      "subtitle" : "test",
      "sound": "default"
	},
  "data": {
    "targetScreen": "order-details",
    "orderId": 9087787
  }
}
@vvusts
Copy link
Author

vvusts commented Jun 17, 2018

Actually I added onMessage and onNotificationDisplayed and it seems when app is in background none of these callbacks are fired when app is in background.
But as I said I get notifications it’s just functions are not triggered.
Same is for onMessage when my payload contains only dara.

@chrisbianca
Copy link
Contributor

Have spoken with @vvusts on discord to clarify this issue.

@orelmax
Copy link

orelmax commented Jun 20, 2018

I have similar issue, but in my case I schedule local notifications, with no payload, and have to increase app icon badge while app is in background. And as in @vvusts case none of the callbacks is being called in background.
@chrisbianca could you share details on how to make it work?

@nerjok
Copy link

nerjok commented Jun 21, 2018

i also got this, notification even with onNotification//.onMessage((message: RemoteMessage) => {console.log()}); empty values notifications gots triggered without onNotification function.

@adcuz
Copy link

adcuz commented Jun 22, 2018

I am seeing this issue too, onMessage does not trigger if the app is running in background (verified by debugger being connected). The notification is shown, however when tapping it, the app moves to foreground but does not trigger the onMessage callback.

This seems to be happening on iOS and Android.

@vvusts
Copy link
Author

vvusts commented Jun 22, 2018

For me onMessage is triggered in background on android but not on ios.
This is why I use notifications on ios and message on android (and create notification manually).
@chrisbianca explained to me that there is some issue with this background things and should probably be solved soon.

@NarendraSingh88
Copy link

@vvusts neither onMessage nor onNotification is getting triggered for me. Can you please suggest how you made it working?

@vvusts
Copy link
Author

vvusts commented Jul 23, 2018

@NarendraSingh88 if you didn't check once more installation documentation.
Don't forget anything in android manifest.
Make sure that your notification/message payload JSON is good.
And make sure that you didn't forget this part: https://rnfirebase.io/docs/v4.2.x/messaging/receiving-messages#4)-(Optional)(Android-only)-Listen-for-FCM-messages-in-the-background

@nerjok
Copy link

nerjok commented Jul 23, 2018

i got it working on android (as @vvusts noted) onMessage() and manual notification display background/foreground. i have left onNotification() asside.

@NarendraSingh88
Copy link

NarendraSingh88 commented Jul 23, 2018

@vvusts onNotification is getting triggered, but only when app is in foreground, but I am stuck for managing it in case of background. Though, the default status bar notification gets displayed in the background, but I need to navigate it to the specific screen on tapping / clicking the notification, and for that I need some callback like onNotification / onMessage in background as well, similar to foreground. Everything is working well, in foreground mode. The issue, I am facing is specifically in the background mode.

@waheedakhter
Copy link

Did anyone find the solution? I am facing exactly the same issue as @NarendraSingh88

@ananth10
Copy link

ananth10 commented Sep 1, 2018

Hello All , Foreground and Background notification working perfectly in Android. but notification received when app in foreground in IOS but notification did not receive when app in background. is this issue still exist in IOS? any solution ?

@laukaichung
Copy link

laukaichung commented Nov 30, 2018

onMessage doesn't work when the app is in background in IOS. As soon as the app is in foreground, all of the notifications sent before are displayed. Neither onMessage nor onNotification gets called when the app is in the background.

@Mai-301
Copy link

Mai-301 commented Dec 21, 2018

@laukaichung background is working in iOS when you listen for onOpen callback

@dikshaonline
Copy link

dikshaonline commented Mar 18, 2019

Hello All ,
I am facing exactly the same issue, Foreground and Background notification working perfectly in Android. but in IOS notification did not receive when app in Foreground. any solution ?

@stefan-stefanica
Copy link

Same issue here

@gatsbys
Copy link

gatsbys commented Jun 20, 2019

@chrisbianca any update on this? Still happening...

@vandiepbui
Copy link

I have same problem. onNotification is triggered on android but not work on ios.
on IOS, onMessage is triggered on foreground but isn't triggered on background and closed app.

Any help?
thanks!

@furkangencer
Copy link

furkangencer commented Sep 9, 2019

I have also the same problem on iOS. When the app is foreground, both onNotification and onNotificaitonDisplayed events are triggered, however when the app is background & killed neither of the events are triggered.

I'm using the versions below. Any help would be really appreciated.
react-native : 0.60.5
react-native-firebase : 5.5.6

@mikehardy
Copy link
Collaborator

@petrucci53 that's just the way iOS works. You kill the app it's dead. I think the google docs have a table that shows all of this?

@jnrana
Copy link

jnrana commented Sep 9, 2019

I am facing same issue.

When i send notification on iOS it triggers onMessage theres is no activity in onNotification event and no banner pops up.
Same thing works fine on android though.

react-native: 0.59.4
react-native-firebase: 5.5.6

podfile

  pod 'Firebase/Core'
  pod 'Firebase/Messaging'

APNs certificates added on firebase settings as well. Nothing seems to work.

@deepankarsandy
Copy link

deepankarsandy commented Oct 21, 2019

@mikehardy .onNotificationOpened() & getInitialNotification() callbacks are not being called on Android only. I've used react-native-splash-screen in my project, is that problem ? android:launchMode="singleTop" I've this on my .MainActivity, but my app starts with .SplashActivity.

onMessage() is working in all conditions on both iOS and Android. iOS is working all fine. Can you please tell if there is any setup I have to do ? @dikshaonline Since your Android setup is working, can you specify your setups ? or put basic codes here ?

@mikehardy
Copy link
Collaborator

@deepankarsandy there is all sorts of setup you need to do. it's all documented on rnfirebase.io though. You also have to be careful of interactions with other modules default setup guides e.g. (code included): crazycodeboy/react-native-splash-screen#289

@deepankarsandy
Copy link

Thank you @mikehardy. It's react-native-splash-screen. This is the solution. https://github.com/invertase/react-native-firebase/issues/1272#issuecomment-421424104

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests