Я использую облачные сообщения React-native и Firebase для отправки уведомления, и я настроил свой проект с Firebase, все работает нормально, и я также получаю уведомление, я создал функцию customDisplayMessage для отображения пользовательского уведомления. он показывает, когда приложение находится на переднем плане.
Я создал здесь один файл util/notification.js и написал свой код следующим образом
Код: Выделить всё
export const notificationListener = () => {
messaging().onNotificationOpenedApp(remoteMessage => {
console.log(
'Notification caused app to open from background state:',
remoteMessage.notification,
);
});
// Check whether an initial notification is available
messaging()
.getInitialNotification()
.then(remoteMessage => {
if (remoteMessage) {
console.log(
'Notification caused app to open from quit state:',
remoteMessage,
);
}
});
};
и я вызываю их в файле app.js
это мой код app.js
Код: Выделить всё
const [displayMessage, setDisplayMessage] = useState(null);
useEffect(() => {
const unsubscribe = messaging().onMessage(async remoteMessage => {
setDisplayMessage(remoteMessage);
CustomMessageDisplay();
console.log('Notification clicked bro');
console.log('Foreground Notification:', remoteMessage);
});
return () => unsubscribe();
}, []);
useEffect(() => {
requestUserPermission();
notificationListener();
getToken();
checkApplicationPermission();
}, []);
Источник: https://stackoverflow.com/questions/781 ... on-in-home