【发布时间】:2020-06-08 12:11:50
【问题描述】:
我正在使用service workers。我需要它用于push 通知。我想要实现的是,当我收到通知时,它应该至少播放声音或振动。
self.registration.showNotification(title, {
body: body,
icon: './assets/images/icons/icon_144x144.png',
vibrate: [200, 100, 200, 100, 200, 100, 200],
});
收到通知后,我得到了这段代码。
问题1:根本没有发生振动。然后我进行了一点调试。
https://googlechrome.github.io/samples/notifications/vibrate.html这不会振动我的手机。
https://googlechrome.github.io/samples/vibration/index.html 这确实会振动我的手机。
为什么它不从第一个链接振动?我正在android chrome 上测试所有这些。
问题 2: 看起来像在 Firefox 上,它确实有默认声音。为什么google没有相同的声音?它只是沉默。没有办法播放声音吗?至少我想振动它...
【问题讨论】:
-
第一个sn-p请求权限。也许他们没有被授予?
-
不幸的是,他们是。 :(
-
你的手机解锁了吗?我的有时在解锁或通知应用处于前台时不振动
-
showNotification方法中去掉了vibrate属性,调用后使用vibrate函数即可
-
验证 chrome 版本。这是支持的版本列表 - developer.mozilla.org/en-US/docs/Web/API/…
标签: android google-chrome push-notification service-worker