cordova - phonegap-plugin-push on("notification") event is not firing when app is in background -
i using following plugin push notification in ionic2
http://ionicframework.com/docs/native/push/
expected behaviour: when app closed, , notification received, , when user tap notification, on("notification") event should fire after app opens.
actual behaviour: getting notification successfully. when application in background or closed, @ time when receive notification , tap notification, on("notification") event not firing.
cordova version 7.0.1 android version 6.2.3
my code:
this.platform.ready().then(() => { this.pushsetup(); }); private pushoptions: pushoptions; private pushobject: pushobject; pushsetup() { // check if have permission this.push.haspermission() .then((res: any) => { if (res.isenabled) { console.log('we have permission send push notifications'); // configuration of push notification this.pushoptions = { android: { senderid: 'xxxxxxxxxxx', icon: 'icon_notification' }, ios: { alert: 'true', badge: true, sound: 'false', senderid: 'xxxxxxxxxxx' }, windows: {} }; this.pushobject = this.push.init(this.pushoptions); // attach push events this.storage.get('ispushregistered') .then(ispushregistered => { if( !ispushregistered ){ this.pushobject.on('registration').subscribe((registration: any) => { console.log('device registered', registration) this.storage.set('ispushregistered', true) }); } }) this.pushobject.on('notification').subscribe((notification: any) => { console.log('received notification', notification) }); this.pushobject.on('error').subscribe(error => console.error('error push plugin', error)); } }); }
so, on code, can see this.pushobject.on('notification') event. not firing when app closed.
thank time , support.
below code has worked me. when app closed, , receive notification. if want handle click event looking payload data. have @ below code:
pushobject.on('notification').subscribe((notification: any) => { // method called when click on notification when app closed pushobject.finish().then(e => { }).catch( e=> { console.log("error notification",e); }) }).catch( e=> { console.log("error notification",e);
})
Comments
Post a Comment