- Home /
Firebase message notification has empty data in body
My server is setup to send notifications to my unity app with custom data in the body, but when received on the unity end, the body field is empty..even the notification data parts. The actual notification itself works fine and is shown on the device, just the data is missing.
I saw someone else had this exact issue here but there was no resolution
https://stackoverflow.com/questions/46219821/firebase-messaging-in-unity-getting-empty-message
Even messages I send from the firebase console with data don't have the data when it hits the client so I don't think my server-side sending logic is the problem. The returned response from sending to the firebase endpoint is always a "success" with no failures too.
Here is my server-side function to send data with no notification. When I call this the Message.From field is set.
def send_message(device_token, data):
url = "https://fcm.googleapis.com/fcm/send"
header = {'Content-Type' : 'application/json',
'Authorization' : 'key=' + os.environ.get('FIREBASE_API_KEY')}
data = {
"data" : data,
"to" : device_token
}
resp = requests.post(url, headers=header, json=data)
print data
print resp.text
return resp.text
This is the method I use to send notification with body data.
def send_notification(to, title, body, data):
url = "https://fcm.googleapis.com/fcm/send"
header = {'Content-Type' : 'application/json',
'Authorization' : 'key=' + os.environ.get('FIREBASE_API_KEY')}
notification = {
"to" : to,
"notification" : {
"title": title,
"body": body
}
}
if data != None:
notification["data"] = data
resp = requests.post(url, headers=header, json=notification)
print resp.text
return resp.text
On Unity client side..heres is my code for OnMessageReceived
private void OnMessageRecieved(object sender, MessageReceivedEventArgs e) {
Debug.Log("Received a new message from: " + e.Message.From);
Debug.Log("Receieved from : " + e.Message.From);
Debug.Log("Raw data is : " + e.Message.RawData);
Debug.Log("TO : " + e.Message.To);
Debug.Log("Message_ID:" + e.Message.MessageId);
Debug.Log ("PRIOIRITY" + e.Message.Priority);
string text = GetFirebaseMessageString (e.Message);
Debug.Log("Raw msg is : " + text);
}
Here is the code for setting the Firebase.Messaging message received callback.
FirebaseMessaging.MessageReceived += OnMessageRecieved;
This currently happens on iOS. Haven't tested android. Currently completely out of ideas on why it is happening. Thought it had something to do with APNS certificates, so I switched to the Auth Key. Made no difference.
Any ideas? Anyone run into this issue? Spent all day on it and have no luck. Really frustrated.
Please help...to avoid this issue I'll have to poll my server like every 20 seconds or so..my bill will go up a ridiculous amount :(
I suspect that this might be a problem with the Firebase Unity SD$$anonymous$$s (not Unity itself). I mean, the SD$$anonymous$$ is responsible for delivering the content of the message, and if it's not delivering the message, it should be the SD$$anonymous$$'s problem... Emphasis here on "I suspect".
$$anonymous$$aybe you should ask a relative question to Firebase support.