【发布时间】:2016-04-23 00:34:29
【问题描述】:
开发Web通知时Chrome Notifications API和Push Notification API有什么区别。什么时候应该使用它们,它们有什么不同?
【问题讨论】:
标签: javascript web-services web notifications push-notification
开发Web通知时Chrome Notifications API和Push Notification API有什么区别。什么时候应该使用它们,它们有什么不同?
【问题讨论】:
标签: javascript web-services web notifications push-notification
通知 API Notifications API 允许网页或应用程序发送在系统级别显示在页面外的通知;这让 Web 应用程序即使在应用程序空闲或在后台也可以向用户发送信息。本文介绍了在您自己的应用中使用此 API 的基础知识。
https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API
推送 API Push API 使 Web 应用程序能够接收从服务器推送给它们的消息,无论 Web 应用程序是否在前台,甚至当前是否在用户代理上加载。这使开发人员可以向选择加入的用户提供异步通知和更新,从而更好地与及时的新内容互动。 https://developer.mozilla.org/en/docs/Web/API/Push_API
查看这些链接了解更多信息: https://www.w3.org/TR/push-api/ https://www.w3.org/TR/notifications/
【讨论】:
这可能会令人困惑,但如果我做对了,自己寻找一个明确的答案,它是这样的:
Notifications API = 用于在用户开启您的网站/应用时发送通知,即使是在空闲或在后台时也是如此。
Push API = 用于在用户不在您的网站/应用时发送通知。
注意:对于 macOS 上的 Safari,Apple 有自己的推送通知 API: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/NotificationProgrammingGuideForWebsites/Introduction/Introduction.html
iOS 上的 Safari 仍然不支持这两种 API 中的任何一种(2021 年 2 月)。
【讨论】: