2

So I have finally implemented a successfull push notification for my website however when i push the notification and suppose the reciever's pc is off , or in sleep mode the gcm returns success but the notification is lost ,it never pops up for that user ...while on the other hand i noticed facebook seems to be doing something that helps it get past this problem .. you see a facebook chrome notification as soon as you open chrome the first thing after a fresh restart ... does any body have any idea as to how fb gets past this problem ??

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Aman Satija
  • 1,865
  • 2
  • 15
  • 16
  • Can we see a snippet of the json you are using to send the push message to GCM? – Miguel Garcia Jan 12 '16 at 14:07
  • i used to not send any flags . all i was sending was ... reg_ids flag .. that's it ...i tried sending the delay when idle flag but that also didn't work ...ill post the json , but marco's answer seems about right .. – Aman Satija Jan 13 '16 at 09:42

1 Answers1

7

If you're using a standard Web Push service (e.g. in Firefox), you need to define a header called 'TTL'. From the standard (https://datatracker.ietf.org/doc/html/draft-ietf-webpush-protocol-02):

An application server can use the TTL header field to limit the time that a push message is retained by a push service. The TTL header field contains a value in seconds that describes how long a push message is retained by the push service.

If you don't set it, the default is 0.

GCM doesn't support the Web Push standard yet, but it does have a time_to_live option that should achieve the same result: https://developers.google.com/cloud-messaging/concept-options#ttl

EDIT: The Mozilla push service now requires the TTL header: https://blog.mozilla.org/services/2016/02/20/webpushs-new-requirement-ttl-header/.

Community
  • 1
  • 1
Marco Castelluccio
  • 10,152
  • 2
  • 33
  • 48
  • 2
    GCM actually does support the protocol (in the shape of an iterative prototype) today, but we're not advertising that in the subscription's endpoint yet: http://www.ietf.org/mail-archive/web/webpush/current/msg00238.html – Peter Beverloo Jan 13 '16 at 19:28