[英]react-native-firebase play custom sound on notification arrived
I have a react native app, Its a react hooks based app, where i want to play custom music based on notification payload data.我有一个反应本机应用程序,它是一个基于反应挂钩的应用程序,我想在其中根据通知有效负载数据播放自定义音乐。 And its working only when app is opened, But i want to play the custom sound when app is in background too.
它仅在应用程序打开时工作,但我也想在应用程序处于后台时播放自定义声音。
useEffect(() => {
checkFirebase();
const firebaseNotification = firebase.notifications().onNotification((notification) => {
console.log("notitication", notification);
const { sound } = notification.data;
console.log("sound", sound);
playSound(sound);
})
return () => {
messageListener();
firebaseNotification();
messageCheck();
}
})
shared my react native code.分享了我的 React 本机代码。 Also sharing the body which i am sending from my Node.js app
还共享我从我的 Node.js 应用程序发送的正文
const message = {
notification: {
title: "Account Deposit",
body: "A deposit to your savings account has just cleared.",
},
android: {
ttl: 3600 * 1000,
notification: {
color: '#ff0000',
sound: 'beep.wav'
}
},
data: {
sound: "beep.wav"
},
token
};
admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
You need something in your application that will allow you to play whilst the app is not focused.您需要在您的应用程序中添加一些东西,让您可以在应用程序不专注时进行游戏。 I've found
react-native-track-player
to be quite good and should provide what you need.我发现
react-native-track-player
非常好并且应该提供你需要的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.