Push FCM con suono garantito su Web, Android e iOS
Payload Firebase Cloud Messaging v1 completo che garantisce il suono di notifica su tutte
le piattaforme — incluso il blocco apns.payload.aps.sound che, se dimenticato, fa arrivare le push mute su iPhone.
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.
Il problema
Una notifica push FCM "corretta" su Android e desktop può arrivare completamente muta su iOS
se manca un blocco specifico nel payload. Il motivo: APNs (Apple Push Notification service) richiede
esplicitamente aps.sound, mentre webpush e Android hanno un suono di default.
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.
Payload completo: webpush + android + apns
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: aggiungilo nel blocco webpush.notification per notifiche che devono restare visibili finché l'utente non le tocca esplicitamente — utile per appuntamenti o eventi critici, a differenza di messaggi chat che possono scomparire da soli.
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.
Attenzione: il blocco apns è obbligatorio per garantire il suono su iPhone — senza apns.payload.aps.sound la notifica viene comunque consegnata, ma in totale silenzio, ed è un bug difficile da scovare perché si manifesta solo su un sottoinsieme di dispositivi.
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.
Perché suono e push si comportano diversamente in background
In-app, il suono via AudioContext funziona solo finché la pagina è aperta e in primo piano —
i browser bloccano l'audio dei tab non visibili per policy di autoplay. Quando la PWA è in background o
chiusa, l'unico modo affidabile per avere suono è delegarlo al sistema operativo tramite push FCM nativa.
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.
Articolo correlato
Calendario Firebase PWA: notifiche push e bug restore sessione — caso reale
Related article
Firebase calendar PWA: push notifications and session restore bug — real-world case
→