繁体   English   中英

收到推送通知(firebase)时如何在后台触发一些声音〜React Native

[英]How to trigger some sound on background when push notification(firebase) received ~ 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)
    }
})

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM