← blog
JavaScript Firebase FCM Multipiattaforma Push notification

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

fcm-payload.js
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.

Related article
Firebase calendar PWA: push notifications and session restore bug — real-world case

When you need this push notification pattern

This snippet shows how to build a Firebase Cloud Messaging v1 payload that guarantees sound on web push, native Android, and iOS all at once, including the apns.payload.aps.sound block often forgotten for iOS.

When to use it

When NOT to use it

Alternatives

Common mistakes

Frequently asked questions about cross-platform push notifications

Because on iOS, sound requires the specific apns.payload.aps.sound block inside the FCM v1 payload: without this section, APNs (Apple Push Notification service) plays no sound even if the notification arrives correctly.

Google has progressively phased out the legacy API in favor of v1, so it's advisable to migrate to the v1 payload structure shown in this snippet to ensure future compatibility.

Yes, web push has its own webpush block in the FCM v1 payload, distinct from the Android one and from APNs for iOS: each has specific fields and behaviors to configure separately.