Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Custom sound does not work when the app is in the background #927

@Hos1g4k1

Description

@Hos1g4k1

My team is using Notifee to show push notifications. We decided to customize the flow by introducing a custom sound for those notifications. After trying to make this work, I managed to implement a custom sound when the app was in the foreground, but I got the default sound when the app was in the background or killed state. After reading a few articles, I am confused about whether this is possible, especially on IOS.

I was researching answers given in this issue but I didn't managed to find the solution for this there - #155

Test flow was next -> log in in the app and gave permissions for notifications. Then, while I am in the foreground I sent one notification and it has the custom sound. Then, I go in the background. Send one more notification and it has the default sound. Same behaviour on Android and on IOS.

Lib versions:

  • "@notifee/react-native": "5.7.0",
  • "@react-native-firebase/messaging": "14.2.4",
  • "react-native": "0.72.6",

My function for showing notifications looks like this

const displayNotification = async (message: FirebaseMessagingTypes.RemoteMessage) => {
  if (shouldDisplayNotification(message.data)){
    await notifee.requestPermission({ sound: true })
    await notifee.displayNotification({
      title: 'message.notification?.title',
      body: 'message.notification?.body',
      data: message.data,
      android: {
        pressAction: { id: 'default' },
        channelId: NOTIFICATION_CHANNEL_ID,
        sound: 'notification'
      },
      ios: {
        sound: 'notification.wav'
      }
    });
  }
};

Creating of Android channel

const createAndroidChannel = async () => {
  await notifee.deleteChannel(NOTIFICATION_CHANNEL_ID);
  await notifee.createChannel({
    id: NOTIFICATION_CHANNEL_ID,
    name: NOTIFICATION_CHANNEL_NAME,
    sound: 'notification'
  });
};

Initialisation of push notifications - getting all permissions

let listener = () => {};

export const initPushNotification = async () => {
  const authorizationStatus = await messaging().requestPermission();

  if (authorizationStatus === messaging.AuthorizationStatus.AUTHORIZED) {
    const token = await messaging().getToken();
    createAndroidChannel();

    listener();
    listener = messaging().onMessage((message: FirebaseMessagingTypes.RemoteMessage) => {
      ...code
      displayNotification(message);
    });

    onForegroundNotification();
    await onBackgroundNotification();
    return Promise.resolve(token);
  }

  return Promise.resolve(null);
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions