question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onNotification is not calling when app is in background

See original GitHub issue

Bug

When I am calling fcm server push notification api data is not showing on onNotification function.

Environment info

react-native info output:

 // paste it here

Library version: 3.4.0

Steps To Reproduce

I use the following code for recieving push notification

  1. Call the service from postman collection for fcm
  2. we got data in onNotification when app is in foreground but not in backgorund …

Describe what you expected to happen:

Reproducible sample code

PushNotification.configure({ // (optional) Called when Token is generated (iOS and Android) onRegister: function (token) { console.log(“TOKEN:”, token); thats.setState({deviceToken:token}); },

  // (required) Called when a remote or local notification is opened or received
  onNotification: function (notification) {
    

    console.log('** NOTIFICATION: **', notification);

  if (Platform.OS === 'ios') {
    if (notification.alert.length !== 0) {
      //handleNotification(notification)
      notification.finish(PushNotificationIOS.FetchResult.NoData);
    }
  } else {
    //handleNotification(notification)
  }

  
  },

  // IOS ONLY (optional): default: all - Permissions to register.
  permissions: {
    alert: true,
    badge: true,
    sound: true,
  },

  // Should the initial notification be popped automatically
  // default: true
  popInitialNotification: true,

 
  requestPermissions: true,
});

PushNotification.popInitialNotification((notification) => { 
  console.log(notification); 
})

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:68 (6 by maintainers)

github_iconTop GitHub Comments

14reactions
Dallas62commented, Jun 11, 2020

This is why onNotification is not trigger. Look at my previous message.

You can’t use notification field with background handler. You must use data (and not combined with notification). Then if you want to notify the user, trigger a local notification.

1reaction
Dallas62commented, Nov 29, 2020

Hi,

There is no channelId defined.

Read more comments on GitHub >

github_iconTop Results From Across the Web

onNotification() is not fired when app is killed - Stack Overflow
I am not positive but when I remember correctly killing (alias force closing) an app disables the onNotification functionality in Android ...
Read more >
Remote push notification doesn't wake up app
The silent push will not wake up the application if it was killed from the app ... Everything works perfectly when the app...
Read more >
Receive messages in an Android app - Firebase - Google
Notification messages delivered when your app is in the background. ... or the app will need to check if it's running in direct...
Read more >
Push notification doesn't open specific screen when app is ...
If it only works in the foreground or the background, ... I close app and tap on notification, nothing happens, like there is...
Read more >
Events | Notifee
In any other situation a Background Event is used instead. ... (e.g. opened another app, pressed the "home" button) but not closed/quit your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found