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);
};
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:
My function for showing notifications looks like this
Creating of Android channel
Initialisation of push notifications - getting all permissions