React-native-push-notification: How can I differentiate notification receive and notification click event

Created on 6 Jul 2016  路  8Comments  路  Source: zo0r/react-native-push-notification

Hi
@zo0r
How can I differentiate notification receive and notification click event
Here I am trying, on notification click move to specific page but if I get any remote notification/click on that notification it goes to
onNotification: function(notification) {
}
Is it possible to know notification open

Most helpful comment

@strwbrry

onNotification: function(notification) {
    const clicked = notification.userInteraction
    if (clicked){
        //do smth
    } else {
        PushNotification.localNotification({
            message: notification.message
        })
    }        

All 8 comments

@zo0r i am having the same problem with differentiating the incoming pushes if it receive and clicked . thanks

@zo0r Any help regarding this issue would be really appreciated.

Oh it worked! Notification object passes a property "foreground" . If its true that means the notification was received while the app was open! Otherwise it was clicked.

@mohitpanjwani what if you clicked the app on the drawer . it will be handled same as when you clicked the notification from the status bar because they are both coming from foreground

@satishkumarkt @xphaul @mohitpanjwani cc
https://github.com/zo0r/react-native-push-notification/issues/122#issuecomment-233709484

I'm having a similar problem. The following is supposed to create a notification when one is received from the server, but if the user clicks on it, it opens another identical one.

onNotification: function(notification) {
    PushNotification.localNotification({
        message: notification.message
    });
}

Is this an incorrect way of display notifications when they're received?

@strwbrry

onNotification: function(notification) {
    const clicked = notification.userInteraction
    if (clicked){
        //do smth
    } else {
        PushNotification.localNotification({
            message: notification.message
        })
    }        

Thanks @zo0r
After update it(notification.userInteraction) works.

Thanks to all comment on this issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nidzovito picture nidzovito  路  3Comments

GastonEDiaz picture GastonEDiaz  路  3Comments

Kiran0791 picture Kiran0791  路  3Comments

Benzer1406 picture Benzer1406  路  3Comments

cidevant picture cidevant  路  3Comments