Meteor-Community-Packages / raix-push

DEPRECATED: Push notifications for cordova (ios, android) browser (Chrome, Safari, Firefox)
https://atmospherejs.com/raix/push
MIT License
514 stars 197 forks source link

background notifications "content-available" flag #318

Closed buymybm100 closed 6 years ago

buymybm100 commented 6 years ago

Hi,

I noticed the event listeners are not called when the App is in background mode. The notification banner is displayed but the event handler is not called.

I have the "contentAvailable" flag set on the Notification object but it makes no difference. The listeners are only called when the app is in foreground mode.

According to the Phonegap-Plugin-Push documentation, setting 'content-available:1' should invoke the listeners if the App is in the background. I believe Morten has added the code for this in the Raix/Push plugin and you have to specify 'contentAvailable:1' in your Notification object.

Am I missing something ? I am trying this on IOS.

Best regards and Many Thanks, Beemer

## Server Push.send({ title : 'MyApp', //no effect. IOS sets this automatically to the name of the App text : formattedMsg, from: 'server', badge: badgeCount, sound: 'default', payload : jsonObjectHere, contentAvailable: 1, query: { userId: alert.toUserId } });

## Client Push.addListener('message', (msg)=>({ // do something with the notification });

Push.Configure({ ios: { alert: true, badge: true, sound: true, clearBadge: true } });

## Server Config Push.Configure({ apn: { certData: Assets.getText(certPath), keyData: Assets.getText(keyPath), passphrase: certPassword, // passphrase you created when exporting your keys production: true, gateway: 'gateway.push.apple.com' }, sendBatchSize: 5 });

ref: Push message arrives with app in background

buymybm100 commented 6 years ago

Found a fix for this. You need an event-handler to listen for the 'startup' message. In other words, you need 2 event-listeners ::

(1) This one listens for messages that arrive when the App is in foreground mode. Push.addListener('message', (msg)=>({ // do something with the notification });

(2) This one to process messages that arrive when the App is in the background. The listener will be called when the User opens up the App again. IOS will invoke the listener for every notification it received while the App was in the background. Push.addListener('startup', (msg)=>({ // do something with the notification });

Hope this helps.

Best regards, Beemer