React-native-push-notification: send payload on local notification?

Created on 6 Mar 2017  路  9Comments  路  Source: zo0r/react-native-push-notification

At usage example described 'data' field of notification object: https://github.com/zo0r/react-native-push-notification#handling-notifications

But I don't see how to use it with local notifications.
Is there any possibilities to send some data with local notification?

Stale

Most helpful comment

@joaovpmamede For some reason data in localNotification params should be a json string (android).

All 9 comments

+1 The same problem. How to send some data in local notifications for android and ios?

I have the same problem on Android.
Tried setting the notification like this:

onNotification(notification) {
    const { foreground, userInteraction, message, data, ...rest } = notification;
    console.log('NOTIFICATION:', notification);

    if (foreground && !userInteraction) {
       PushNotification.localNotification({ ...rest, data, message });
    }
    ...
}

I have the same problem

You can use userInfo for iOS

@joaovpmamede For some reason data in localNotification params should be a json string (android).

@AlimovSV thank you so much. Got this working at last :)

Now I just need to find a way to get the notification object when the app is closed and I click on a notification.
I do get the object when I receive the push notification though.

send by

PushNotification.localNotification({
    //..........
    data: JSON.stringify({type: 'news', content: 'news one title'})
})

Parse by

PushNotification.configure({
    onNotification: function(notification) {
        let json = notification.data;
        console.log(json.type);
    },

});

Why is it necessary to put my data in a userInfo object for iOS? I see an empty data object when I send a local notification.

EDIT: I see that it maps userInfo to data object that can get handled by onNotification

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anativ picture anativ  路  3Comments

selimonline picture selimonline  路  3Comments

atteia picture atteia  路  4Comments

Kiran0791 picture Kiran0791  路  3Comments

sungjinoh picture sungjinoh  路  3Comments