FCM push with guaranteed sound on Web, Android and iOS
Complete Firebase Cloud Messaging v1 payload that guarantees notification sound across
all platforms — including the apns.payload.aps.sound block which, if forgotten, makes pushes arrive silent on iPhone.
The problem
A push notification that's "correct" for Android and desktop can arrive completely silent on iOS
if a specific payload block is missing. The reason: APNs (Apple Push Notification service) explicitly
requires aps.sound, while webpush and Android have a default sound.
Full payload: webpush + android + apns
const msg = { message: { token, // Browser desktop e Android via PWA webpush: { headers: { Urgency: 'high' }, notification: { title, body, tag, silent: false, // esplicito: usa suono di sistema requireInteraction: requireInteraction } }, // Android nativo android: { priority: 'HIGH', notification: { sound: 'default', default_sound: true } }, // iOS — senza aps.sound la push arriva MUTA apns: { headers: { 'apns-priority': '10' }, payload: { aps: { sound: 'default', 'content-available': 1 } } }, data: strData } };
requireInteraction: add it in the webpush.notification block for notifications that must stay visible until the user explicitly dismisses them — useful for appointments or critical events, unlike chat messages that can disappear on their own.
Warning: the apns block is mandatory to guarantee sound on iPhone — without apns.payload.aps.sound the notification still gets delivered, but completely silent, and it's a hard bug to spot because it only manifests on a subset of devices.
Why sound and push behave differently in background
In-app, sound via AudioContext only works while the page is open and in the foreground —
browsers block audio in non-visible tabs due to autoplay policy. When the PWA is in the background or
closed, the only reliable way to get sound is to delegate it to the OS via native FCM push.