使用 Service Worker 向所有人发送推送通知
Send Push Notification to everyone with Service Worker
curl --header "Authorization: key=blahblahblah" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"blahblahblah\"]}"
目前我可以通过上面的命令发送推送通知。为了向用户发送通知,我需要从用户那里获取注册 ID。如果我想向所有人(订阅该通知的人)推送通知怎么办?我如何获得他们的注册 ID?
*注意:我想要的是:当我在网站上的东西更新时向所有人推送通知。
Link 到我的项目:Github
我从这里学习了推送通知+软件:Google Developer
你需要registration_ids
(因此是复数)给你想发送推送给的每个人。
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.
非常相似的问题是 Google Cloud Messaging send notification to all devices
您需要做的是在后端数据存储中跟踪所有客户端的注册 ID,然后在从后端进程发送通知时使用所有这些注册 ID。在真实世界的系统中,这不可能全部在客户端完成 - curl
技巧在示例前端代码中作为解决缺少后端的 hack。
我知道有几个不同的后端示例:
- https://github.com/jeffposnick/gh-notifier,它使用 Firebase + Node.js.
- https://github.com/gauntface/simple-push-demo-backend,它使用 Python App Engine。
- https://github.com/johnmellor/push-api-appengine-demo,它使用 Python App Engine。
- https://github.com/googlechrome/ioweb2015,它使用 Go App Engine。
curl --header "Authorization: key=blahblahblah" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"blahblahblah\"]}"
目前我可以通过上面的命令发送推送通知。为了向用户发送通知,我需要从用户那里获取注册 ID。如果我想向所有人(订阅该通知的人)推送通知怎么办?我如何获得他们的注册 ID?
*注意:我想要的是:当我在网站上的东西更新时向所有人推送通知。
Link 到我的项目:Github
我从这里学习了推送通知+软件:Google Developer
你需要registration_ids
(因此是复数)给你想发送推送给的每个人。
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.
非常相似的问题是 Google Cloud Messaging send notification to all devices
您需要做的是在后端数据存储中跟踪所有客户端的注册 ID,然后在从后端进程发送通知时使用所有这些注册 ID。在真实世界的系统中,这不可能全部在客户端完成 - curl
技巧在示例前端代码中作为解决缺少后端的 hack。
我知道有几个不同的后端示例:
- https://github.com/jeffposnick/gh-notifier,它使用 Firebase + Node.js.
- https://github.com/gauntface/simple-push-demo-backend,它使用 Python App Engine。
- https://github.com/johnmellor/push-api-appengine-demo,它使用 Python App Engine。
- https://github.com/googlechrome/ioweb2015,它使用 Go App Engine。