Pushwoosh / pushwoosh-phonegap-plugin

Pushwoosh PhoneGap Build Plugin
Other
109 stars 139 forks source link

Possible (benign?) bug with multiple events being called #218

Closed rwillett closed 7 years ago

rwillett commented 7 years ago

Hi,

We accidently left an old PushWoosh 4.2.2 registration event 'push-notification' in some code we were testing on iOS 8.4 using PushWoosh 6.2.6.

document.addEventListener('push-notification', HandlePushWooshIOSNotificationPushNotificationType); // THIS IS FOR OLDER VERSIONS OF PUSHWOOSH
document.addEventListener('push-receive', HandlePushWooshIOSNotificationPushReceiveType); // THIS IS FOR NEWER VERSIONS OF PUSHWOOSH

When we send a content-available=1 notification down to the device AND the device is in the foreground THEN both events 'push-notification' and 'push-receive' are fired.

The behaviour changes when the device is in the background AND the app has not been suspended

When we send a content-available=1 notification down to the device AND the device is in the background THEN only the 'push-receive' event is fired.

Our code handles multiple (and possibly duplicate) events being received and sorts it all out, so it's not a problem for us (for once) and I suspect the bug is reasonably benign, but we would have thought that the behaviour should be consistent whether the device is in the foreground or background.

Also the docs for Cordova http://docs.pushwoosh.com/docs/cordova-phonegap still refer to the event 'push-notification' when we believe they should refer to 'push-receive'.

Thanks Rob

wfhm commented 7 years ago

Hi,

This is an expected behaviour: 'push-notification' event is fired when a push is opened, while 'push-receive' is fired when a push is received. So, when in foreground, your app automatically handles all incoming pushes, therefore both events are fired. When in background, however, you do not click on a notification (you don't even have such an option when sending a silent push), so only the latter event is triggered.

rwillett commented 7 years ago

Ah!

So we seem to have magically found the right way of working purely by accident :)

Might be good to get the docs updated though.

Rob