【发布时间】:2020-01-22 14:56:28
【问题描述】:
我有一个 react native 应用程序,它是一个基于 react hooks 的应用程序,我想根据通知负载数据播放自定义音乐。它只在应用打开时工作,但我也想在应用处于后台时播放自定义声音。
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);
});
【问题讨论】:
标签: firebase react-native react-native-firebase