OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Ionic, PhoneGap CLI, PhoneGap Build, Cordova, or Sencha Touch app with OneSignal. Supports Android, iOS, and Amazon's Fire OS platforms. https://onesignal.com
Other
251
stars
199
forks
source link
[Bug]: OneSignal.initialize is no longer idempotent on Android #1015
The collection of listeners does not seem to be a Set and this is added to the listeners again and again. The end result is that the JS click event listener is called once for every invocation of OneSignal.initialize.
This causes problems in applications that are not 100% SPAs and navigate between different parts of the app using full-page reloads. In such a case, it is very difficult to determine if OneSignal.initialize has already been called or not and an idempotent version is much easier to use.
It can also cause problems when developing applications and using hotswapping/live reload.
Create a test app that calls `OneSignal.initialize(appId)` several times
Click on a push notification
Registered click listeners will be called repeatedly
What did you expect to happen?
I expect to be able to call OneSignal.initialize(appId) as often as I want without any side effects on Android.
A simple solution would be to add a new isInitialized field to the OneSignalPush class and only add this as a listener if it has not been set.
OneSignal Cordova SDK version
5.2.4
Which platform(s) are affected?
[ ] iOS
[X] Android
Relevant log output
No response
Code of Conduct
[X] I agree to follow this project's Code of Conduct
What happened?
OneSignal.initialize(appId)
used to be idempotent on iOS and Android. Since https://github.com/OneSignal/OneSignal-Cordova-SDK/commit/3c94a25887d90b468c80597fe3236f46658620dd, this is no longer the case on Android.Currently, every time
OneSignal.initialize(appId)
is called, the current instance ofOneSignalPush
is added as a listener:https://github.com/OneSignal/OneSignal-Cordova-SDK/blob/1e2f9e7763bc22c4c4f59d27d974676283b5c4d3/src/android/com/onesignal/cordova/OneSignalPush.java#L360-L364
The collection of listeners does not seem to be a
Set
andthis
is added to the listeners again and again. The end result is that the JSclick
event listener is called once for every invocation ofOneSignal.initialize
.This causes problems in applications that are not 100% SPAs and navigate between different parts of the app using full-page reloads. In such a case, it is very difficult to determine if
OneSignal.initialize
has already been called or not and an idempotent version is much easier to use.It can also cause problems when developing applications and using hotswapping/live reload.
Most likely related issues:
Steps to reproduce?
What did you expect to happen?
I expect to be able to call
OneSignal.initialize(appId)
as often as I want without any side effects on Android.A simple solution would be to add a new
isInitialized
field to theOneSignalPush
class and only addthis
as a listener if it has not been set.OneSignal Cordova SDK version
5.2.4
Which platform(s) are affected?
Relevant log output
No response
Code of Conduct