I use Firebase Cloud Messaging to send notifications on Flutter.
Some notifications of my chat application are repeated, for example, when 3 messages are sent in a chat, 3 notifications are sent.
I want the previous notifications to be deleted and only the last notification to be displayed
send it with a data message, not a notification
{
"to":"_some_fcm_token_",
"type": "new_message",
"data": {
"model":{"id":"same_user_notification_id"},
"body": "subtitle",
"title": "title",
"click_action": "FLUTTER_NOTIFICATION_CLICK"
},
"priority": "normal"
}
this is different between Message types :
Notification message
Data message
About FCM messages
Related
I am implementing the firebase cloud messaging to make my push notification service for a project but I am at a block, if I close down the tab which means I close my flutter web application I do not get the notifications that were sent whilst the time my app was closed in my browser.
I have looked through different threads here suggesting i remove the notification key from the message I am sending to FCM.
Please refer to the payload sent:
> {
"to" :[ "xxxxxxxxxx"]
"data" : {
"body" : "Notification Body",
"title": "Notification Title",
"key_1" : "Value for key_1f",
"key_2" : "Value for key_2"
}
}
The problem though still remains when I close the tab running my flutter web app and send a notification, I do not receive it when I open the app in a new tab again.
Essentially I have to provoke the onMessageReceived() function but I guess this would not be in my case. Is it different because the thread(link) are based on mobile apps and not web applications.
`
I have integrated the Huawei Push kit to my app and when I trigger a notification from Huawei Push Kit Console, I can receive the notification when the app is in background. However, when our system backend triggers Huawei API to push notifications, it doesn't appear when the app is in the background.
Following code is getting executed despite the app is in foreground or background but Notification parameters such as Title etc, coming as null. Notification object itself is not null.
Contents of the JSON message can be received as a single String from remoteMessage.getData() but values does not mapped to respective fields.
public class HuaweiNotificationHandler extends HmsMessageService{
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.i(TAG, "getData: " + remoteMessage.getData()
RemoteMessage.Notification notification = remoteMessage.getNotification();
if (notification != null) {
Log.i(TAG, "getTitle: " + notification.getTitle()
}
}
}
Our backend executes this API provided by Huawei to send data messages.
This is the format of our JSON
{
"collapseKey":"dummykey",
"priority":"high",
"delayWhileIdle":false,
"dryRun":false,
"sound":"",
"contentAvailable":true,
"data":{
"data":{
"type":"A",
"id":"1111111",
"entity":"0",
"url":""
},
"restrictedPackageName":"com.aa.bb.cc" // this package name is exactly same as the huawei app package registered
},
"notification":{
"title":"Notification Title",
"icon":"ic_launcher",
"body":"Message"
}
}
UPDATE
Sample code of a typical data message:
{
"validate_only": false,
"message": {
"data": "{'param1':'value1','param2':'value2'}",
"token": [
"pushtoken1",
"pushtoken2"
]
}
}
For Details,see Docs.
Push Kit supports two types of messages: notification messages and data messages.
After a device receives a data message, the device transfers it to your app instead of directly displaying the message. Your app then parses the message and triggers the corresponding action. Push Kit only functions as a channel, and the delivery of data messages depends on the resident status of your app. However, notification messages can still be delivered even if your app is not launched.
For the sake of saving power and not disturbing users, your app will not be launched by Push Kit after being stopped, and no data messages can be delivered to your app. In this case, you can determine whether to use notification messages based on your services.
From: https://stackoverflow.com/a/64100678/14006527
Alternatively, you can set High-priority data messages to forcibly launch your stopped app to receive and process the messages.
I am trying to track email "open" event on Sendgrid. I have enabled Open tracking in Tracking setting in my Sendgrid account. I have also enabled Event webhook under Mail settings->Event Settings and I have enabled event webhook for all the events.
When I send the email, I get the event webhook response for "processed" and "delivered" events but if I open the emails I don't get any webhook response. I tried opening the email in Outlook and in Gmail in chrome browser.
Is there anything else to be done that I am missing? Please help.
Below is the response I get for processed and delivered mails.
[
{
"OrderId": "5555",
"email": "myemail#gmail.com",
"event": "processed",
"send_at": 0,
"sg_event_id": "cHJvY2Vzc2VkLTE3NTE3NjIzLV9PbGs1ZWx4U1VHUUZSTUk3aVBlY0EtMA",
"sg_message_id": "_Olk5elxSUGQFRMI7iPecA.filterdrecv-p3iad2-865cf6bb5-sddvl-18-5F560026-42.0",
"smtp-id": "<_Olk5elxSUGQFRMI7iPecA#ismtpd0002p1lon1.sendgrid.net>",
"timestamp": 1599471654
},
{
"OrderId": "5555",
"email": "myemail#gmail.com",
"event": "delivered",
"ip": "167.89.12.138",
"response": "250 2.0.0 OK 1599471656 r7si5783789ejy.514 - gsmtp",
"sg_event_id": "ZGVsaXZlcmVkLTAtMTc1MTc2MjMtX09sazVlbHhTVUdRRlJNSTdpUGVjQS0w",
"sg_message_id": "_Olk5elxSUGQFRMI7iPecA.filterdrecv-p3iad2-865cf6bb5-sddvl-18-5F560026-42.0",
"smtp-id": "<_Olk5elxSUGQFRMI7iPecA#ismtpd0002p1lon1.sendgrid.net>",
"timestamp": 1599471656,
"tls": 1
}
]
First of all, check the settings
Next, check your setting for engagement data
Finally, check your mail clients are allowed to download images and have any extensions block ads or not
Sendgrid will add a transparent 1-pixel image at the bottom of email, if with any reason cannot load this picture, you won't receive opened event
I had the same problem, you need to go to settings-> tracking and make sure open and click events are enabled.
Sorry if this is a dumb question, I am setting up Firebase with APNs for the first time. I am working in Swift with an iOS app and I have apns messages working separately without Firebase -- so remote push notifications are received on the device in background and while running app. I can use this tool https://github.com/noodlewerk/NWPusher to send notifications on Sandbox and Production apns certs successfully by sending this json blob as an example:
{"aps":{"alert":"Testing","badge":1,"sound":"default"}}
However, now I am trying to incorporate Firebase and not getting the same behavior on the iOS device.
I have Firebase messaging setup and the app prints remote messages with "shouldEstablishDirectChannel = true" but APNs is never received (with this set to false then device doesn't print anything). No push notifications are received on device. I don't believe APNs is being mapped correctly for Firebase messages as I cannot get the device to display push notifications in the same way that I can with NWPusher on strictly APNs Sandbox and Production certs. Firebase app console has the app's .p12 apns cert (which is working fine for apns without firebase involved)
Here's a sample request I try to send to https://fcm.googleapis.com/fcm/send
{
"to" : "eqkeyhereinifnbe",
"collapse_key" : "type_a",
"data" : {
"body" : "Notification",
"title": "testing",
"key_1" : "Data for key one",
"key_2" : "Hello Meowww",
}
}
API returns a success response:
{
"multicast_id": 634054476369,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:15329261441bfd36cccfb49c"
}
]
}
In iOS app's AppDelegate:
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)!")
}
^prints the message successfully from the api on device:
Received data message: [AnyHashable("collapse_key"): type_a,
AnyHashable("key_1"): Data for key one, AnyHashable("from"): 9861340,
AnyHashable("key_2"): Hello Meowww, AnyHashable("body"): Notification,
AnyHashable("title"): testing]!
However this received message doesn't do any of the APNs notification magic to an iOS device. I tried to send the same json blob to Firebase API that works fine in NWPusher: {"aps":{"alert":"Testing","badge":1,"sound":"default"}}, but device does not display the notification. Why? How troubleshoot this to make Firebase send the same APNs notification to show notifications on device?
I just needed to write the request with "message" and "data" objects like this:
{
"to" : "aTokenHerefonsfondfodnfdofndf",
"collapse_key" : "type_a",
"notification":{
"title":"Notification title test",
"body":"It worked body"
},
"data" : {
"body" : "Notification",
"title": "testing",
"key_1" : "Data for key 1",
"key_2" : "Hello Meowww"
}
}
I want to implement the FCM Push Notification service for a chat app, I follow the step in the Firebase doc , Im getting notifications when they are sent from the Firebase console to my device.
When I try to send the notification using my server side to the device through FCM using http post to https://fcm.googleapis.com/fcm/send :
my headers are :
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
my body is :
{ "notification": {
"title": "Portugal vs. Denmark",
"text": "5 to 1"
},
"to" : "myDeviceRegistrationId"
}
When my app is in background , nothing is happening (I repeat myself but with the console, I am getting the notification in background )
When the app is active and I am sending this notification to my device, Im getting the following message in my console Log, So I suppose that I am getting the notification but for some reason its not displaying it in background
Message ID: 0:1470132526023119%8d989dbf8d989dbf
%# [aps: {
alert = {
body = "5 to 1";
title = "Portugal vs. Denmark";
};
}, gcm.message_id: 0:1470132526023119%8d989dbf8d989dbf]
2016-08-02 13:08:46.913 ProjectAlpha[13324:4726432] Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.
what am I missing ?
thanks for your help..
Did you active background mode?
Look this
I fixed my issue by deleting the
FirebaseAppDelegateProxyEnabled
key from Info.plist and using
"content_available": true
to receive messages while application is in background.
Now it works perfectly :)