收到通知时反应本机firebase播放自定义声音
我有一个react原生应用程序,它是一个基于react挂钩的应用程序,我想根据通知负载数据播放自定义音乐。它只在应用程序打开时工作,但我想在应用程序处于后台时播放自定义声音收到通知时反应本机firebase播放自定义声音,firebase,react-native,react-native-firebase,Firebase,React Native,React Native Firebase,我有一个react原生应用程序,它是一个基于react挂钩的应用程序,我想根据通知负载数据播放自定义音乐。它只在应用程序打开时工作,但我想在应用程序处于后台时播放自定义声音 useEffect(() => { checkFirebase(); const firebaseNotification = firebase.notifications().onNotification((notification) => { console.log("noti
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();
}
})
共享我的本地代码。还共享我从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);
});
你需要在你的应用程序中加入一些东西,让你在应用程序不集中的时候玩。我发现react native track player相当不错,应该可以满足您的需要。您建议的是一个可以播放声音的库,我可以使用react native audio来播放声音。但我想知道firebase通知何时到达,我如何捕获该通知数据,或者我只想播放声音。我理解这一点,但你还需要一个库,在你的应用程序处于后台时播放声音。您当前的库不会为您这样做。因此,为了获得所需的解决方案,您需要解决一系列问题。您知道如何处理后台通知吗?使用react native firebase。我正在尝试编写一个桥接器,它将发送和事件以响应本机代码。任何替补队员都会帮上大忙