When browser is closed, every push notification that has been sent in the meantime is queued up, which leads to receiving hundreds of notifications when I open the browser for the first time next day. Is there a way of stopping push notifications queuing up?
3 Answers
1
votes
An option is to make use of time_to_live:
This parameter specifies how long (in seconds) the message should be kept in FCM storage if the device is offline. The maximum time to live supported is 4 weeks, and the default value is 4 weeks. For more information, see Setting the lifespan of a message.
and set it to your desired time. Basically it determines until only when FCM would keep the message on the queue.
0
votes
There are two options:
- when you make the request to the push service you can include a
TTLheader (in seconds) for the notification, so that it expires if it is not delivered within that time - you can use a
tagfor the notifications when you display them to hide the older notifications that belong to the same group (tag)
0
votes
For those using web push c# library the code reference to this is something like below:
public void SendPushNotification(PushSubscription sub)
{
var pushEndpoint = sub.EndPoint;
var p256Dh = sub.P256dh;
var auth = sub.Auth;
const string subject = @"mailto:[email protected]";
var publicKey = PushConfiguration.PublicKey; //configuration attribute coming from the web.config file
var privateKey = PushConfiguration.PrivateKey; //configuration attribute coming from the web.config file
var subscription = new PushSubscription(pushEndpoint, p256Dh, auth);
var vapidDetails = new VapidDetails(subject, publicKey, privateKey);
var options = new Dictionary<string, object> {{"TTL", 3}, {"vapidDetails", vapidDetails}};
var myPayload = new NotificationData(){// my data};
var webPushClient = new WebPushClient();
try
{
webPushClient.SendNotification(subscription, myPayload , options);
}
catch (WebPushException exception)
{
Console.WriteLine("Http STATUS code" + exception.StatusCode);
}
}