【发布时间】:2018-02-05 02:57:22
【问题描述】:
我正在使用 Ionic Native FCM 在我的 Android Ionic 2 应用程序上实现推送通知
当我在前台收到通知时,它可以工作,但是当我在后台收到通知并且单击它时,什么也没有发生。
app.component.ts
firebaseInit(){
//Firebase
this.fcm.subscribeToTopic('all');
this.fcm.getToken()
.then(token => {
console.log(token);
this.nativeStorage.setItem('fcm-token', token);
});
this.fcm.onNotification().subscribe(
data => {
console.log("NOTIF DATA: " + JSON.stringify(data));
if(data.wasTapped){
this.nav.push(MemoViewPage, {memo: {_id: data.memo_id}})
console.info('Received in bg')
}else{
let alert = this.alertCtrl.create({
title: data.subject,
message: "New memorandum",
buttons: [
{
text: 'Ignore',
role: 'cancel'
},
{
text: 'View',
handler: () => {
this.nav.push(MemoViewPage, {memo: {_id: data.memo_id}})
}
}
]
});
alert.present();
console.info('Received in fg')
}
});
this.fcm.onTokenRefresh()
.subscribe(token => {
console.log(token);
})
}
单击系统托盘中的通知后,if(data.wasTapped) 条件不会消失。
编辑
应用程序打开但仅在主页中而不是我设置的指定页面this.nav.push(MemoViewPage, {memo: {_id: data.memo_id}})
当应用程序被终止或未运行时,我也无法收到通知。
【问题讨论】:
-
您应该使用
NavController让应用程序打开特定页面。 -
你也可以使用本地推送通知而不是 FCM,这在我的经验中要好得多
-
@KevinRED NavController 在 app.component.ts 中不起作用,它说没有提供程序,并且在 app.module.ts 下插入 NavController 时出现错误
-
我相信你可以在脚本的服务器端做一些事情,你可以查看这个链接了解更多信息github.com/phonegap/phonegap-plugin-push/blob/master/docs/…
标签: android firebase ionic2 firebase-cloud-messaging cordova-plugin-fcm