且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当浏览器在后台运行时收到通知时,使用Firebase播放声音

更新时间:2022-12-27 11:45:02

虽然目前不支持声音,但您应该能够在从服务工作者内部显示通知时振动用户的设备。这可能足以引起他们的注意。 (如果你真的需要...)

While sounds are not currently supported, you should be able to vibrate a user's device when showing a notification from inside of a service worker. That might be sufficient to get their attention. (If you really need to...)

以下是实时样本

registration.showNotification('Vibration Sample', {
  body: 'Your title here.',
  icon: 'path/to/icon.png',
  vibrate: [200, 100, 200, 100, 200, 100, 200],
  tag: 'vibration-sample'
});