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 fired when application is in the background while pushing remote notifications

See original GitHub issue

Hi, I am experiencing strange behaviour while pushing notifications. It seems that when my application in the background, onNotification callback is invoked and it is even called with userInteraction: true which does not make sense at all. It does not always invoke, and I wonder what is the right behaviour for this.

I think that onNotification should not be invoked right away, but it should invoke only after the user clicked on the push notification with userInteraction: true.

I have not changed anything in my configuration and just used the documentation example:

// (optional) Called when Token is generated (iOS and Android)
onRegister: function(token) {
    console.log( 'TOKEN:', token );
},

// (required) Called when a remote or local notification is opened or received
onNotification: function(notification) {
    console.log( 'NOTIFICATION:', notification );

    // process the notification

    // required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
    notification.finish(PushNotificationIOS.FetchResult.NoData);
},

// ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
senderID: "YOUR GCM SENDER ID",

// 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,

/**
  * (optional) default: true
  * - Specified if permissions (ios) and token (android and ios) will requested or not,
  * - if not, you must call PushNotificationsHandler.requestPermissions() later
  */
requestPermissions: true,

Did anyone encounter this? Thanks in advance!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
EdgarHSMcommented, Aug 6, 2020

I also followed the example in the documentation and I’m having a similar issue on iOS, as soon as the device receives a push notification while the app is in the background (not closed, just “minimized”), onNotification is triggered and the “userInteraction” flag is true, it doesn’t wait for the user to click on the notification.

1reaction
stevenconnercommented, May 10, 2018

I’m experiencing the same issue. When receiving a notification in background when app is ‘dead’ (force quit, or hasn’t been ran for a while), the app starts automatically from the background without user interaction on the notification. Would love to get this resolved! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

onNotification() is not fired when app is killed - Stack Overflow
i'm using https://github.com/zo0r/react-native-push-notification to ...
Read more >
Push notification in Background wo… | Apple Developer Forums
Push notification in Background works fine when App runs by Xcode, but does not work when App runs by itself.
Read more >
react-native-push-notification - npm
React Native Local and Remote Notifications for iOS and Android ... changes in the application part, while localNotificationSchedule() only ...
Read more >
Handling Incoming Push Notifications in AWS Amplify - Medium
AWS Amplify provides two push notification configuration functions to configure how push notifications are handled by your app: onNotification, ...
Read more >
Handling Incoming Push Notifications in AWS Amplify
PushNotification.onNotification ; If the app is in the foreground ; or in the background ; handler function is called when a push notification...
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