Using RN=0.39, on Android.
I've set this up and all of the GCM stuff with data is working great; I send a message and the onNotification() function in my app fires, and the data looks right.
But I don't see anything in the Android notification area. Am I missing something? It doesn't seem to be mentioned anywhere in the README.
@GeoffreyPlitt
Test with your app in background.
@jaisonveneri I did that, and all that happened is the "foreground" value is false instead of true. I'm able to tell this from my console.logs, but there's no UI showing the push notification. Any advice? Is this working for anyone?
Update: I'm cross-posting an issue I left at https://github.com/ToothlessGear/node-gcm/issues/281, because I think the data format is the key to my problem.
I'm trying to use this library to receive PN's on a phone, sent from a Node server using https://github.com/ToothlessGear/node-gcm/issues/281. I'm testing on a real device, and I've got some GCM connection working, because I can see received message in my logs, but the notifications do not show in the UI (device's notification area), and I think it's because of a disparity in the documentation regarding the message schema.
I've tried several different example messages, pulled from your docs, their docs, or other places, and I'm showing the resulting message received. I'm pretty confused, and I can't find a way that seems to allow both "notification" and "data" parts through. In fact, it seems like "data" is the only part that goes through, which may explain my issue. As a side note, part of the problem seems to be that the data is sometimes collapsed from JSON to string, is that happening in your lib for some reason? As another side note, is this related to FCM vs GCM?
Each of the example messages below is sent to sender.send(message, { registrationTokens: tokens }, ...)
const example1 = {
collapseKey: 'demo',
priority: 'high',
contentAvailable: true,
timeToLive: 3,
data: {
key1: 'message1',
key2: 'message2'
},
notification: {
title: "Hello, World",
icon: "ic_launcher",
body: "This is a notification that will be displayed ASAP."
}
}
// RESULT:
// {
// collapse_key: "com.stardust"
// foreground: true
// google.message_id: "0:1484096257740237%7ee359d17ee359d1"
// google.sent_time: 1484096257734
// id:"-1643774423"
// key1:"message1"
// key2:"message2"
// userInteraction:false
// }
const example2 = {
time_to_live: 86400,
collapse_key: "new_message",
delay_while_idle: false,
notification: {
title: "title",
body: "this is a noisy test",
tag: "new_message",
icon: "new_message",
color: "#18d821",
sound: "default"
}
}
// RESULT:
// {
// collapse_key:"com.stardust"
// foreground:true
// google.message_id:"0:1484096278293346%7ee359d17ee359d1"
// google.sent_time:1484096278289
// id:"-762117123"
// userInteraction:false
// }
const example3 = {
data: {
info: {
subject: "Hello GCM2",
message: "Hello from the server side!"
}
}
// RESULT
// {
// collapse_key: "do_not_collapse"
// foreground: true
// google.message_id:"0:1484096309107031%7ee359d1f9fd7ecd"
// google.sent_time:1484096309103
// id:"-1292255135"
// info:"{\"subject\":\"Hello GCM2\",\"message\":\"Hello from the server side!\"}"
// userInteraction:false
// }
If it helps, here are the ADB logs for each of the 3 examples. Does this prove that the needed fields are being dropped somewhere in server/GCM side?
# Example 1
01-11 13:03:42.564 3874 4195 V RNPushNotification: onMessageReceived: Bundle[{google.sent_time=1484168622619, key1=message1, key2=message2, google.message_id=0:1484168622623549%7ee359d17ee359d1, notification=Bundle[{body=This is a notification that will be displayed ASAP., icon=ic_launcher, title=Hello, World}], collapse_key=com.stardust}]
01-11 13:03:42.574 3874 3874 V RNPushNotification: sendNotification: Bundle[{google.sent_time=1484168622619, userInteraction=false, id=-1832792420, key1=message1, key2=message2, google.message_id=0:1484168622623549%7ee359d17ee359d1, notification=Bundle[{body=This is a notification that will be displayed ASAP., icon=ic_launcher, title=Hello, World}], collapse_key=com.stardust, foreground=true}]
# Example 2
01-11 13:05:36.234 3874 3893 V RNPushNotification: onMessageReceived: Bundle[{google.sent_time=1484168736136, google.message_id=0:1484168736140266%7ee359d17ee359d1, notification=Bundle[{tag=new_message, body=this is a noisy test, icon=new_message, color=#18d821, sound=default, title=title}], collapse_key=com.stardust}]
01-11 13:05:36.254 3874 3874 V RNPushNotification: sendNotification: Bundle[{google.sent_time=1484168736136, userInteraction=false, id=-1973474245, google.message_id=0:1484168736140266%7ee359d17ee359d1, notification=Bundle[{tag=new_message, body=this is a noisy test, icon=new_message, color=#18d821, sound=default, title=title}], collapse_key=com.stardust, foreground=true}]
# Example 3
01-11 13:06:20.334 3874 3895 V RNPushNotification: onMessageReceived: Bundle[{google.sent_time=1484168780187, info={"subject":"Hello GCM2","message":"Hello from the server side!"}, google.message_id=0:1484168780190275%7ee359d1f9fd7ecd, collapse_key=do_not_collapse}]
01-11 13:06:20.344 3874 3874 V RNPushNotification: sendNotification: Bundle[{google.sent_time=1484168780187, userInteraction=false, id=-14455439, info={"subject":"Hello GCM2","message":"Hello from the server side!"}, google.message_id=0:1484168780190275%7ee359d1f9fd7ecd, collapse_key=do_not_collapse, foreground=true}]
Solved. If anyone else has these issues, here's what fixed it for me:
{
collapseKey: 'demo',
priority: 'high',
contentAvailable: true,
timeToLive: 3,
data: {
key1: 'message1',
key2: 'message2'
},
notification: {
title: "Hello, World",
icon: "ic_launcher",
body: "This is a notification that will be displayed ASAP."
}
}
I have a question about the callback. How can I see the response of the local notification? with pushNotification.onNotification?
Do I need something to declare first?
Most helpful comment
Solved. If anyone else has these issues, here's what fixed it for me: