当浏览器关闭时,同时发送的每个推送通知都会排队,这会导致第二天第一次打开浏览器时收到数百个通知。有没有办法阻止推送通知排队?
答案 0 :(得分:1)
选项是使用time_to_live
:
此参数指定如果设备处于脱机状态,则应在FCM存储中保留消息的时间长度(以秒为单位)。支持的最长生存时间为4周,默认值为4周。有关详细信息,请参阅Setting the lifespan of a message。
并将其设置为您想要的时间。基本上,只有当FCM将消息保留在队列中时才会确定。
答案 1 :(得分:0)
对于那些使用web push c#库的人来说,对此的代码引用如下所示:
public void SendPushNotification(PushSubscription sub)
{
var pushEndpoint = sub.EndPoint;
var p256Dh = sub.P256dh;
var auth = sub.Auth;
const string subject = @"mailto:xyz@xyz.com";
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);
}
}
答案 2 :(得分:0)
有两种选择:
TTL
标头(以秒为单位),以便在该时间内未送达时过期tag
通知when you display them来隐藏属于同一组(标记)的旧通知