Send Push Notification to everyone with Service Worker

3.2k views Asked by At
curl --header "Authorization: key=blahblahblah" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"blahblahblah\"]}"

Currently i am able to send push notification though the command above. In order to send the notification to user, i need to get the registration id from user. What if I want to push notification to everyone (who subscribed to that notification)? And how I get their registration ID?

*Note: what I want is: push a notification to everyone when my something in the website updated.

Link to my project: Github

I learnt push notification + sw from here: Google Developer

2

There are 2 answers

0
Jeff Posnick On BEST ANSWER

What you'd need to do is keep track of the registration ids for all of your clients in a backend datastore, and then use all of those registration ids when sending notifications from a backend process. It can't all be done client side in a real-world system—the curl trick is there in the sample frontend code as a hack to work around the lack of a backend.

There are a few different backend examples out there that I know about:

0
Karol Klepacki On

You need registration_ids (therefore plural) for everyone you want to send Push to.

An array of registration_ids - these are just the subscriptionId’s you’d have for the users you would like to send a push message to.

Very similar issue is Google Cloud Messaging send notification to all devices