evollu / evollu/react-native-fcm

Not getting notification via FCM.on or FCM.getInitialNotification

Open
#771 40 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.7k
Forks
661
PR merge metrics
No merged PRs in 30d

Description

Hi,

I'm seeing similar issue reported in https://github.com/evollu/react-native-fcm/issues/569, but not sure if it is exactly the same.. In some cases, when i click on the notification toast, i get the notification properly in my app in the FCM.on callback that i have as follows:

FCM.on(FCMEvent.Notification, async (notif) => {
logger.log("received notification: " + JSON.stringify(notif))
handleNotification(notif) // my code to handle the notification
}

However, in one particular case, the above code doesn't get invoked. This is when I wait for a long time (say, 15+ minutes) before I click/tap on the notification toast. I think Android puts the app to sleep after that much time?

I am also already checking for FCM.getInitialNotification as follows.. (the code below is invoked from one of my componentDidMount methods)..

FCM.getInitialNotification().then(notif => {
if(notif){
logger.log('Got initial notificaton: ' + JSON.stringify(notif))
NotificationUtil.handleNotification(notif)
}
}
I do get something in the above block (initial notification), but its kind of empty. the log statement above is:

Got initial notificaton: {"opened_from_tray":1,"fcm":{"action":null}}

And this happens only when I wait for a while before i click/tap on the notification toast (not sure if some folks here are calling that a 'banner' - which is available when you swipe/pull down from the top of the phone screen)..

If the app is just minimized, and i tap on the notification toast in a couple of minutes, everything works fine - my FCM.on callback gets invoked, and i get the complete notification data as expected.. here's one log for the success case:

received notification: {"fcm":{"action":"my_test_action"},"show_in_foreground":true,"data.foo":"bar","sound":"default","opened_from_tray":1,"click_action":"my_test_action","priority":"high","id":"my_notif_id","body":"test notif body","title":"test notif title","icon":"ic_launcher","local_notification":true}

@evollu - do you know what could be causing this?

Thanks
Amit

When openning an issue, please include following information for better support

1. What version of RN and react-native-fcm are you running?
"react": "^16.2.0",
"react-native": "^0.51.0",
"react-native-fcm": "^11.3.1",

2. What device are you using? (e.g iOS9 emulator, Android 6 device)?
Android 7.1.1 emulator (same behavior on many other versions, as well as my Samsung s8+ running 7.1.1)..

3. Is your app running in foreground, background or not running?
not running

Before openning an issue
1. Reproduce it with the example project in this repo.
2. If you can't receive iOS notification, make sure you can receive notification using quickstart-ios project provided by Firebase team

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.