I use native notify to get notifications and they work perfectly in the background. But when I am inside the app and send myself a notification, nothing happens. It should trigger my function onRefresh(), as it does when I get the notification in background.
useEffect(() => { (async () =>
{ const { status } = await Notifications.requestPermissionsAsync();
if (status !== 'granted')
{ alert('Permission for notifications not granted!');
} })(); }, []);
useEffect(() => { Notifications.setNotificationHandler({ handleNotification: async () => ({ shouldShowAlert: true, shouldPlaySound: true, shouldSetBadge: false, }), });
notificationListener.current = Notifications.addNotificationReceivedListener(notification => {
console.log('Notification received in foreground:', notification);
setNotification(notification);
onRefresh();
});
responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
console.log('Notification response received:', response);
onRefresh();
});
return () => {
if (notificationListener.current) {
Notifications.removeNotificationSubscription(notificationListener.current);
}
if (responseListener.current) {
Notifications.removeNotificationSubscription(responseListener.current);
}
};}, []);`
I expect the notification to trigger my onRefresh(), when inside my app
New contributor
Amar Tahirović is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.