-
Notifications
You must be signed in to change notification settings - Fork 380
Open
Labels
Description
How can we help?
Consider this part of App.tsx (I'm on RN 0.71 and react-native-onesignal 5.2.8):
const handleForegroundNotification = (event: any) => {
console.log("Foreground Notification Detail:", JSON.stringify(event));
// play MP3 using https://github.com/zmxv/react-native-sound
const cash_register_sound = new Sound(
"cash.mp3",
Sound.MAIN_BUNDLE,
(error) => {
if (error) {
console.log("Failed to load the sound", error);
return;
}
cash_register_sound.play((success) => {
if (success) {
// Do another thing, like play speech with react-native-tts
} else {
console.log("Playback failed due to audio decoding errors");
}
});
},
);
cash_register_sound.setVolume(0.75);
cash_register_sound.setPan(1);
cash_register_sound.stop();
cash_register_sound.release();
event.notification.display();
};
OneSignal.Notifications.addEventListener(
"foregroundWillDisplay",
handleForegroundNotification,
);
Assuming app is in foreground, then after OneSignal notification is received, a "ka-ching "sound followed by "Payment accepted: XX USD" is played. So far so good on both Android & iOS devices.
Of course it won't be triggered if app is in background/minimzed. Does react-native-onesignal provide such support, or do I have to write additional code using native API?
Code of Conduct
- I agree to follow this project's Code of Conduct