0

I am building an application similar to Swiggy, So When getting a new order from a customer, I am triggering a push notification, At that time I need to trigger a different Horn Sound.

Modules used:

// For Firebase notification
@react-native-firebase/messaging
react-native-push-notification (for local notification)


// Background lisner to trigger sound
import messaging from '@react-native-firebase/messaging';
import SoundPlayer from 'react-native-sound-player'

messaging().setBackgroundMessageHandler(async(remoteMsg) => {
    try {
        SoundPlayer.playSoundFile('air_horn', 'mp3')
    } catch (e) {
        console.log(`cannot play the sound file`, e)
    }
})

Here! The problem is Sound is not triggered when notification is received.

Please Help me with this. Thanks in advance.

Premji
  • 69
  • 1
  • 6

1 Answers1

0

Set sound field into push notification payload https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support

Vasyl Nahuliak
  • 1,912
  • 2
  • 14
  • 32