回答

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隱藏屬於同一組的較舊通知(標記)