我实现了Web推送通知。虽然通知已经发送成功,但我想要播放我添加的自定义通知声音,而不是系统默认的窗口声音。我希望能够播放这个声音。我在代码中添加了一些内容以了解为什么无法播放这个通知声音。
self.addEventListener('push', async function (event) {
const data = event.data.json();
console.log(data);
const title = 'Sound Notification';
const options = {
sound: '../public/messageNotification.mp3',
};
try {
registration.showNotification(title, options);
} catch (e) {
registration.showNotification(title, options);
}
});