我使用下面的推送通知插件在Ionic2上(“通知”)事件的PhoneGap-插件推不点火当应用程序在后台
http://ionicframework.com/docs/native/push/
预期的行为: 当应用程序被关闭,并收到通知,并且当用户点击通知时,on(“通知”)事件应该在应用程序打开后触发。
实际行为: 我收到通知成功。但是当应用程序处于后台或关闭状态时,当我收到通知并点击通知时,(“通知”)事件不会触发。
科尔多瓦版本7.0.1 Android版本6.2.3
我的代码:
this.platform.ready().then(() => {
this.pushsetup();
});
private pushOptions: PushOptions;
private pushObject: PushObject;
pushsetup() {
// to check if we have permission
this.push.hasPermission()
.then((res: any) => {
if (res.isEnabled) {
console.log('We have permission to 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 a notification', notification)
});
this.pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}
});
}
所以,在我的代码,你可以看到this.pushObject.on ('通知')事件。当应用程序关闭时不会触发。
谢谢你的时间和支持。
你有没有设置“内容-available“:1表示从后端发送的有效负载数据。 – Vasanth
是的,我设定了它。但仍然没有成功。另外,我已经阅读了phonegap插件文档,其统计如下:“如果用户已经杀死了应用程序,则不会进一步处理推送数据。” https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#push-message-arrives-with-app-in-background –
当应用程序关闭时,您将无法执行电话差距推送的任何功能。但是当它在后台时,你可以通过设置“content-available”来执行:1. – Vasanth