回答

1

一种选择是利用time_to_live

此参数指定消息应该多长时间(以秒计)被保持在FCM存储如果设备处于离线状态。支持的最长时间为4周,默认值为4周。有关更多信息,请参见Setting the lifespan of a message

并将其设置为您所需的时间。基本上它决定了直到FCM才将消息保留在队列中。

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:[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); 
     } 
    } 
0

有两种选择:

  • 时,你的请求推服务,您可以包含一个TTL标头(以秒为单位)通知,以便在该时间内没有递送时过期
  • 您可以使用tag作为否通知when you display them隐藏属于同一组的较旧通知(标记)