Pushwoosh / pushwoosh-phonegap-plugin

Pushwoosh PhoneGap Build Plugin
Other
110 stars 139 forks source link

IOS Content-available when in background mode not working - Defect found in 6.2.0? #201

Closed rwillett closed 7 years ago

rwillett commented 8 years ago

We think we may have found a defect in the Cordova plugin 6.2.0.

We've recently upgraded from PushWoosh 4.2.2 to PushWoosh 6.2.0 and have found different behaviour (or a bug) in the two different versions of the plugin on IOS. Our app has been out for over a year and this is the first time we have wanted to upgrade all our plugins. Until now its been very reliable.

Very Short Summary

Under the PushWoosh plugin V6.2.0 on IOS 8.4, the javascript function registered with

document.addEventListener('push-notification', HandlePushWooshIOSNotification);

doesn't appear to get called when an event with a silent notification is sent to the app AND the app is in the background. The function does get called when the app is in the foreground.

Under PushWoosh plugin 4.2.2 the function gets called for both foreground and background which is the correct behavior.

Short Summary

_PushWoosh behaviour on 4.2.2_

Our server sends a content-available=1 (a slient push) to our app.

If our app is in the foreground, the silent push event is captured and a function call is made to our JavaScript function "HandlePushWooshIOSNotification". We process this in our app.

If our app is in the background, he silent push event is captured and a function call is made to our JavaScript function "HandlePushWooshIOSNotification".We process this in our app.

This is the expected behaviour and we can see that it works as expected. This code has been running for around 18 months for us.

_PushWoosh behaviour on 6.2.0_

Our server sends a content-available=1 (a slient push) to our app.

If our app is in the foreground, the silent push event is captured and a function call is made to our JavaScript function "HandlePushWooshIOSNotification". We process this in our app.

If our app is in the background, we can see that the event has been captured by the PushWoosh plugin (logs below), but our JavaScript function "HandlePushWooshIOSNotification" is never called and no error is logged (as far as we can see). This is the problem.

We know that a number of changes were made to the PushWoosh plugin between these two versions, e.g. the data format has changed, the deviceToken has changed to from deviceToken to pushToken, but as far as we can see the method to handle events,

document.addEventListener('push-notification', HandlePushWooshIOSNotification);

has not changed. We've managed the data format changes easily, since we can see that our HandlePushWooshIOSNotification is called when in the foreground we can see the correct data formats being passed in. We never even get the call to HandlePushWooshIOSNotification when in the background.

We test the background functionality immediately we put the app in the background. We know that if the app goes in the background for more than 15 mins, it can get suspended. We also handle this but in a different way on our server rather than the client.

Long summary

We can see from the logs when our function HandlePushWooshIOSNotification gets called. So long as our function is called, we can handle it and its our problem. However PushWoosh does not seem to call the function.

Cordova Plugin 4.2.2 Foreground

This works correctly and we can see HandlePushWooshIOSNotification called

2016-09-12 09:39:11.619 Jambuster[3126:358402] ================ 2016-09-12 09:39:11.620 Jambuster[3126:358402] ===== HandlePushWooshIOSNotification: event = {"notification":{"aps":{"content-available":1},"p":"1j","onStart":false}} 2016-09-12 09:39:11.620 Jambuster[3126:358402] ================ 2016-09-12 09:39:11.672 Jambuster[3126:359243] [PW] [I] -[PWRequestManager sendRequestInternal:withDict:error:] x | Pushwoosh request: | Url: https://cp.pushwoosh.com/json/1.3/pushStat | Payload: {"request":{"device_type":1,"hash":"1j","application":"A2EE0-23D28","userId":"USERID_CHANGED_TO_PROTECT_THE_INNOCENT","v":"3.1.1.434","hwid":"USERID_CHANGED_TO_PROTECT_THE_INNOCENT"}} | Status: "200 no error" | Response: {"status_code":200,"status_message":"OK","response":null} x 2016-09-12 09:39:11.675 Jambuster[3126:359243] [PW] [D] -[PushNotificationManager sendStatsBackground:] sendStats completed 2016-09-12 09:39:11.687 Jambuster[3126:359248] [PW] [I] -[PWRequestManager sendRequestInternal:withDict:error:] x | Pushwoosh request: | Url: https://cp.pushwoosh.com/json/1.3/setBadge | Payload: {"request":{"device_type":1,"badge":0,"application":"A2EE0-23D28","userId":"USERID_CHANGED_TO_PROTECT_THE_INNOCENT","v":"3.1.1.434","hwid":"USERID_CHANGED_TO_PROTECT_THE_INNOCENT"}} | Status: "200 no error" | Response: {"status_code":200,"status_message":"OK","response":null} x 2016-09-12 09:39:11.689 Jambuster[3126:359248] [PW] [D] -[PushNotificationManager sendBadgesBackground:] setBadges completed

Cordova Plugin 4.2.2 Background

This works correctly and we can see HandlePushWooshIOSNotification called

2016-09-12 09:36:03.209 Jambuster[3126:358578] [PW] [I] -[PWRequestManager sendRequestInternal:withDict:error:] x | Pushwoosh request: | Url: https://cp.pushwoosh.com/json/1.3/pushStat | Payload: {"request":{"device_type":1,"hash":"1u","application":"A2EE0-23D28","userId":"USERID_CHANGED_TO_PROTECT_THE_INNOCENT","v":"3.1.1.434","hwid":"USERID_CHANGED_TO_PROTECT_THE_INNOCENT"}} | Status: "200 no error" | Response: {"status_code":200,"status_message":"OK","response":null} x 2016-09-12 09:36:03.211 Jambuster[3126:358578] [PW] [D] -[PushNotificationManager sendStatsBackground:] sendStats completed 2016-09-12 09:36:03.263 Jambuster[3126:358581] [PW] [I] -[PWRequestManager sendRequestInternal:withDict:error:] x | Pushwoosh request: | Url: https://cp.pushwoosh.com/json/1.3/setBadge | Payload: {"request":{"device_type":1,"badge":0,"application":"A2EE0-23D28","userId":"USERID_CHANGED_TO_PROTECT_THE_INNOCENT","v":"3.1.1.434","hwid":"USERID_CHANGED_TO_PROTECT_THE_INNOCENT"}} | Status: "200 no error" | Response: {"status_code":200,"status_message":"OK","response":null} x 2016-09-12 09:36:03.264 Jambuster[3126:358581] [PW] [D] -[PushNotificationManager sendBadgesBackground:] setBadges completed 2016-09-12 09:36:03.277 Jambuster[3126:358402] ================ 2016-09-12 09:36:03.278 Jambuster[3126:358402] ===== HandlePushWooshIOSNotification: event = {"notification":{"aps":{"content-available":1},"p":"1u","onStart":false}} 2016-09-12 09:36:03.279 Jambuster[3126:358402] ================

Cordova Plugin 6.2.0 Foreground

This works correctly and we can see HandlePushWooshIOSNotification called

2016-09-12 09:42:09.242 Jambuster[3141:359949] [PW] [D] -[PushNotification onPushAccepted:withNotification:onStart:] Notification opened: { foreground = 1; ios = { aps = { "content-available" = 1; }; p = "1m"; }; onStart = 0; } 2016-09-12 09:42:09.249 Jambuster[3141:359949] ================ 2016-09-12 09:42:09.249 Jambuster[3141:359949] ===== HandlePushWooshIOSNotification: event = {"notification":{"onStart":false,"foreground":true,"ios":{"aps":{"content-available":1},"p":"1m"}}} 2016-09-12 09:42:09.250 Jambuster[3141:359949] ================ 2016-09-12 09:42:09.250 Jambuster[3141:359949] HandlePushWooshIOSNotification: got silent notification 2016-09-12 09:42:09.250 Jambuster[3141:359949] ===== 2016-09-12 09:42:09.250 Jambuster[3141:359949] HandleNotificationEvent: event 2016-09-12T09:42:09Z -> {"contentAvailable":true,"isActive":true,"originalPushWooshEvent":{"onStart":false,"foreground":true,"ios":{"aps":{"content-available":1},"p":"1*m"}}} 2016-09-12 09:42:09.250 Jambuster[3141:359949] ===== 2016-09-12 09:42:09.250 Jambuster[3141:359949] HandleNotificationEvent: adding GetNotificationsFromServer to Execution queue

Cordova Plugin 6.2.0 Background

This is where we expect to see our function HandlePushWooshIOSNotification called. We can see that the PooshWoosh plugin captures the silent notification, but it just disappears and nothing else happens.

2016-09-12 09:30:08.677 Jambuster[3106:356563] [PW] [D] -[PushNotification] Notification opened: { foreground = 0; ios = { aps = { "content-available" = 1; }; p = "1h"; }; onStart = 0; } 2016-09-12 09:30:08.741 Jambuster[3106:356843] [PW] [I] -[PWRequestManager] x | Pushwoosh request: | Url: https://cp.pushwoosh.com/json/1.3/pushStat | Payload: {"request":{"device_type":1,"hash":"1h","application":"A2EE0-23D28","userId":"USERID_CHANGED_TO_PROTECT_THE_INNOCENT","v":"4.0.4.","hwid":"USERID_CHANGED_TO_PROTECT_THE_INNOCENT"}} | Status: "200 no error" | Response: {"status_code":200,"status_message":"OK","response":null} x 2016-09-12 09:30:08.743 Jambuster[3106:356843] [PW] [D] -[PushNotificationManager] sendStats completed

We aren't 100% clear if this is bug in the PushWoosh plugin, but we've spent the last few days trying to work it out and can't see what we are doing wrong.

We are using ioS 8.4 on our phone. Thats deliberate as some of our customers haven't upgraded.

Any help or guidance gratefully received, even if its to say we've done something stupid.

Thanks

Rob

DimanAM commented 8 years ago

There is a separate push-receive event that was introduced in 6.1.0. It is triggered when application is aware of push notification arrival (when notification is received in foreground or when notification contains content-available flag). This event works on Android as well. In a fact push-notification event was originally intended to be used for handling push notification alerts. It is triggered when user taps on notification or when notification is received in foreground and autohandling is enabled.

rwillett commented 8 years ago

Ok, thanks.

Is this documented?

We went through the cordova docs and they use the push-notification event in the examples.

We'll try it out and see what happens.

Rob

StefanoMagrassi commented 7 years ago

@rwillett it seems it's not documented, but in the source code there are some useful (I hope) comments: line 440 and line 448 in www/PushNotification.js

rwillett commented 7 years ago

Thanks for this. Its the sort of thing that should be in the docs front and centre.

Rob