首页 > 解决方案 > 收到推送通知(firebase)时如何在背景上触发一些声音〜React Native

问题描述

我正在构建一个类似于Swiggy的应用程序,因此当从客户那里获得新订单时,我正在触发推送通知,此时我需要触发不同的喇叭声音。

使用的模块:

// 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)
    }
})

这里!问题是收到通知时未触发声音。

请帮我解决一下这个。提前致谢。

标签: androidfirebasereact-nativereact-native-sound

解决方案



推荐阅读