Open akeva001 opened 1 year ago
Hello @akeva001 would you be able to send the logs from your device reproducing this behavior? We'll be happy to investigate. Thanks!
I have the same issue. Listeners are not getting removed on reload when developing locally.
I stumbled across this log because I have just realised that in my own development environment the click event defined below is literally firing 45 (and growing) times when the application starts.......and no notifications have been clicked at all! :(
OneSignal.Notifications.addEventListener('click', async (event) => {
logger.info('Push notification clicked:', event)
})
Seems consistent with HMR in play.
You can call
OneSignal.Notifications.clearAll()
before adding event listener to clear all previous listeners
You can call
OneSignal.Notifications.clearAll()
before adding event listener to clear all previous listeners
Is there documentation regarding that method that states that it will remove existing listeners? The SDK just says Removes all OneSignal notifications.
which is pretty ambiguous to say the least.
The SDK just says
Removes all OneSignal notifications.
which is pretty ambiguous to say the least.
You are right. It's about removing notifications.
This problem still persists. Has anyone solved it?
` useEffect(() => { const onForegroundWillDisplay = async (event: any) => { event.preventDefault(); console.log('OneSignal: notification will be displayed', event);
// Perform async work here
const result = await dispatch(
GetNotificationThunk({userId: user.id as string}),
);
// Display the notification after async work
event.getNotification().display();
};
// Add the event listener
OneSignal.Notifications.addEventListener(
'foregroundWillDisplay',
onForegroundWillDisplay,
);
// Cleanup function to remove the event listener on unmount or before re-render
return () => {
OneSignal.Notifications.removeEventListener(
'foregroundWillDisplay',
onForegroundWillDisplay,
);
};
}, [dispatch]); // Add dispatch to dependency array if needed`
I am facing the same problem eventListener is getting called multiple. times
i stil fight with this problem :) can anyone tell how to solve this? my app always listen event click when open the app or reload the app
i stil fight with this problem :) can anyone tell how to solve this? my app always listen event click when open the app or reload the app
I doubt you will see the problem in production. It is usually just a symptom of the dev environment - especially if you use HMR
i stil fight with this problem :) can anyone tell how to solve this? my app always listen event click when open the app or reload the app
I doubt you will see the problem in production. It is usually just a symptom of the dev environment - especially if you use HMR
So if i try to build with APK release mode or AAB, the above problem will not occur right?
How can we help?
I am using the event listeners as described in the setup guide, but when I receive a notification, the events fire more than 10 times. How can I fix this?
Code of Conduct