Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: addEventListener is triggering a few of times #957

Open
3 tasks done
lautaro-corfield opened this issue Jan 3, 2024 · 3 comments
Open
3 tasks done

[Bug]: addEventListener is triggering a few of times #957

lautaro-corfield opened this issue Jan 3, 2024 · 3 comments

Comments

@lautaro-corfield
Copy link

lautaro-corfield commented Jan 3, 2024

What happened?

I have the following code:
In app.component.ts:
this.platform.ready().then(async () => { this.oneSignalNotificationService.bindNotifications(); });

In onesignal.service.ts:
bindNotifications(): void { OneSignal.initialize(environment.onesignalAppId); console.log("bindNotifications"); OneSignal.Notifications.addEventListener('click', async (e) => { console.log("eventListener"); //Something else }); }
bindNotifications is displayed only once per console but eventListener is executed more than 30 times.

Steps to reproduce?

1. Build application
2. Initialize the application
3. Send notification
4. Click on the notification

What did you expect to happen?

bindNotifications to be displayed only once and eventListener to be displayed only once for each time a notification is clicked.

OneSignal Cordova SDK version

5.0.3

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jennantilla
Copy link
Contributor

Thanks for your patience, @lautaro-corfield! We're woking on reproducing this and investigating further.

@theigl
Copy link

theigl commented Aug 19, 2024

We ran into a similar issue today. Our app is not a pure SPA and we do full-page navigation from time to time. Every time this happens, platform.ready() is fired again and another listener is added. Removing the listener before adding it does not help, because the remove is not propagated from JS to the native layer. It only removes the listener from JS.

This was not an issue in previous versions of the SDK because it used OneSignal.setNotificationOpenedHandler and the previous listener was replaced.

I think there should be an option to clear existing listeners, or listeners should automatically be cleared when OneSignal.initialize is called.

See a similar discussion on the OneSignal for Flutter: OneSignal/OneSignal-Flutter-SDK#763

@theigl
Copy link

theigl commented Aug 20, 2024

@jennantilla: Please let me know if you need more information. This issue is important to us and we can provide additional info if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants