Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data vs Display notifications #324

Open
0x62 opened this issue Aug 3, 2018 · 1 comment
Open

Data vs Display notifications #324

0x62 opened this issue Aug 3, 2018 · 1 comment

Comments

@0x62
Copy link

0x62 commented Aug 3, 2018

In this SO post they discuss the difference between data and display messages (the main difference being data messages trigger the onMessageReceived() callback even if your app is in foreground/background/killed).

I've been trying to use this library (through node-pushnotifications) but it appears the messages are being sent as display notifications. How do I change the type to data so the callback will be triggered even if the app is in the background?

@eladnava
Copy link
Collaborator

eladnava commented Aug 3, 2018

Hi @0x62,
Using this sample code only a data payload is sent and not a notification display payload:

var gcm = require('node-gcm');

// Set up the sender with your GCM/FCM API key (declare this once for multiple messages)
var sender = new gcm.Sender('YOUR_API_KEY_HERE');

// Prepare a message to be sent
var message = new gcm.Message({
    data: { key1: 'msg1' }
});

// Specify which registration IDs to deliver the message to
var regTokens = ['YOUR_REG_TOKEN_HERE'];

// Actually send the message
sender.send(message, { registrationTokens: regTokens }, function (err, response) {
	if (err) console.error(err);
	else console.log(response);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants