let messages = {
registration_ids: tokenId,
notification: {
title: 'WebServer',
body: 'Message from center'
},
data: { result: { type: 'add', data : 'New Record' }, sender: {'first_name': 'James', 'last_name': 'Antony' } },
};
fcm.send(messages, function (err, response) {
if (err) {
return err
console.log("Something has gone wrong!", err);
} else {
console.log("Successfully sent with response: ", response.results);
}
});
Can we send object inside data i.e result can supply type and message.
If I put inside object it does not send notification but if I do toString() it does work but at mobile end it shows [object][object].
How can we Make it correct.
The data
node can only contain string values. It cannot contain more complex values, such as objects.
If you want to send more complex data, encode it as a string in your message, and decode that string in your application code. For example, you can use JSON.stringify
and JSON.parse
to send JSON objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With