I have implemented firebase cloud messaging in my app and I wish to implement silent push notification.
I have done all the necessaries and send the following json post request to my app.
{
"to": "/topics/news",
"notification": {
"title": "Portugal vs. Denmark",
"body": "5 to 1"
},
"content_available": true,
"priority": "normal"
}
The app successfully receives the notification when it is in background, but the notification is still displayed as banner (I believe silent notification means there will not be any badge, banner displaying right?)
If you want your notifications to be silent, they have to contain only data payload, with no notification content. So, you should remove this:
"notification": {
"title": "Portugal vs. Denmark",
"body": "5 to 1"
}
Review message types for more details.
Related
I want to redirect to a specific page on remote push notification tap in my flutter app. So I fire the following JSON payload from the backend,
{
"to": "cMXdSK_ud0LpqMoju85FvT:APA91bFMke92QR1IvcLeLhG5XrvwcE0OfSLGpJW1ds9-FFDornoeorMlKOn6IEtDYsuvwlRrwJnHJy0BPl_udcbqac39WF---------------------",
"notification": {
"title": "Krunal Here",
"body": "Test notification Krunal",
"product_id" : "124",
"content_available": true,
},
"data": {
"title": "Krunal Here",
"body": "Test notification Krunal",
"product_id" : "124",
"content_available": true,
},
"priority" : "high"
}
Notifion received on both Android and iOS devices. But I face 3 problems,
Android phone received 2 notifications, I think one local notification generate automatically because I used "notification" keyword in the payload.
(I removed "notification" object from the payload and pass only "data" it works fine in the android app but didn't receive any notification on the iOS device. So must have used "notification" keyword that I found, Event I tried to use "aps" keyword but iPhone did not receive any notification.)
iOS App redirection is not working because I didn't get product_id from the payload.
If I use both "notification" & "data" notifications received on both apps. (Android received 2 notifications as I mention above) But redirection is not working in any app.
What is the correct payload format for the flutter app? Can you please help me to find this solution?
I have developed a flutter application and integrated Firebase notification and firebase phone authentication.
I am able to do phone authentication both on development mode as well as after the app is published
I am able to receive notification when the app is development mode - but when I publish the app I dont receive the notification.
I should point out here that I am able to receive the notification if I send it from the firebase console (even after the app is published) - but I do not receive notification from my panel after the app is published (but the same is working absolutely fine otherwise)
I should also point out that this problem is only faced with iOS and not android.
What am I missing?
When you are sending notification to mobile phone using firebase push notification service then make sure the payload is set correctly in order to successfully deliver the notification to mobile phone.
The basic example of the payload for FCM is as follows.
{
"to": "<FCM TOKEN OF DEVICE>",
"data": {
"key1": "value1",
"key2": "value2"
},
"priority": "high",
"notification": {
"body": "This is body",
"title": "This is title",
"sound": "default"
},
"message": {
"notification": {
"title": "This is title",
"body": "This is body"
}
}
}
You can go through this article to know more about FCM service and its payload.
EDIT
Also you need to make sure that the correct certificate is uploaded on the firebase console.
You can export those certificate from the keychain.
I'm having a weird issue with FCM, specifically when sending silent push notifications to iOS devices.
Here is the JSON we were sending on the HTTP request to Firebase four days ago:
{
"to": "<firebase token>",
"content_available": true
}
Today, that JSON no longer works. Based on this StackOverflow response, I tried adding the sound property like so:
{
"to": "<firebase token>",
"content_available": true,
"notification": {
"sound": ""
}
}
Now this works. I shouldn't need to specify an empty sound property on this in order to get it working.
For context, these are things that do work:
Sending non-silent push notifications through Firebase Cloud Messaging
Sending silent and non-silent push notifications directly through APNs
Anyone have an idea on what's going on?
I'm migrating from Parse to Firebase and facing a problem with our ios app.
The Firebase API does not send push notifications to the ios app.
This is what im sending to https://fcm.googleapis.com/fcm/send
{
"to: "<registration token>",
"priority": "high",
"data": {
"customId": "<my custom id>",
"badge": 1,
"sound": "cheering.caf",
"alert": "New data is available"
}
}
And the server is returning success
{
"multicast_id":6917019914327105115,
"success":1,
"failure":0,
"canonical_ids":0,
"results":[{"message_id":"0:1468961966677585%f0f84693f9fd7ecd"}]
}
But the push is not delivered.
If I sent the push using the Firebase Dashboard, the pushes are delivered, even if I targeting directly with the Token.
I saw another developer complaining in another Stackoverflow question
Can't send push notifications using the server API
I tried their solution of adding the "priority": "high", it did not fixed the issue. But it gave me a clue: They are also using the dev/sandbox push certificate.
My suspicion is that the Dashboard can use the ios Development certificate, but the API can not. The problem only happen on the ios device, since the android app are getting the pushes through API.
Is anyone able to send pushes using the API and the development certificate?
I got contacted by Firebase support and was able to find out what is wrong
My push payload was missing a notification object
{
"to": "<registration token>",
"priority": "high",
"notification": {
"title": "Your Title",
"text": "Your Text"
}
"data": {
"customId": "<my custom id>",
"badge": 1,
"sound": "cheering.caf",
"alert": "New data is available"
}
}
I hope that helps someone else
The object you send to https://fcm.googleapis.com/fcm/send with Firebase API should look like this :
{
"notification":{
"title":"Notification title", //Any value
"body":"Notification body", //Any value
"sound":"default", //If you want notification sound
"click_action":"<activity_name>", //Must be present for Android
"icon":"fcm_push_icon" //White icon Android resource
},
"data":{
"param1":"value1", //Any data to be retrieved in the notification callback
"param2":"value2"
},
"to":"/topics/topicExample", //Topic or single device
"priority":"high", //If not set, notification won't be delivered on completely closed iOS app
"restricted_package_name":"" //Optional. Set for application filtering
}
Please if your problem has been solved don't forget to mark it as such.
I have a question.For iOS,Can we send both "data" and "notification" in the payload?I was getting the notification when only "notification" was sent to the GCM.When I added both,I am not getting any notification.My question is,What should be the payload if I want to get update on both iOS and android devices?
current payload :
{
"to":"/topics/testTopic",
"content_available":true,
"priority":"high",
"notification": {
"body":"Test Message",
"title":"test"
},
"data": {
"title": "Title.D Mixed JSON",
"body": "Content.D Mixed JSON",
"productId" : "1"
}
}
Your payload is fine, there is no reason that you should not be getting it. But there are some differences between those two.
Difference between "notification" and "data" is documented in official documentation: https://developers.google.com/cloud-messaging/concept-options
Use notifications when you want GCM to handle displaying a notification on your client app’s behalf. Use data messages when you want your app to handle the display or process the messages on your Android client app, or if you want to send messages to iOS devices when there is a direct GCM connection
So, for you hybrid messages that you want to send it is important to know if your app is in the background or in the foreground:
When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification.
When in the foreground, your app receives a bundle with both payloads available.
Another reason for not receiving push notifications is that you have not assigned delivery priority. There are two options normal and high.
High
High priority. GCM attempts to deliver high priority messages immediately, allowing the GCM service to wake a sleeping device when possible and open a network connection to your app server
Normal
Normal priority. This is the default priority for message delivery. Normal priority messages won't open network connections on a sleeping device, and their delivery may be delayed to conserve battery
Try to set "priority" : "high" right before "notification" in your payload.
It's not Allowed to duplicate the content of "notification" and "data", you can read the data inside the "notification" when the user tap on the notification, the following JSON should work with you.
{
"to":"/topics/testTopic",
"content_available":true,
"priority":"high",
"notification": {
"body":"Test Message",
"title":"test"
},
"data": {
"productId" : "1"
}
}