我正在使用Ionic和FCM(firebase)插件发送推送通知。我可以收到通知,当我点击通知时它会成功触发警报,但它不会导航到指定的选项卡。只是为了确定这一行:
this.tab.select(2);
我已经测试过使用按钮导航该代码并且可以正常工作
FCMPlugin.onNotification(function(data){
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
alert('data was tapped');
this.tab.select(2);
//this.navCtrl.push(ViewurgentnewsPage); also tried this
}else{
//Notification was received in foreground. Maybe the user needs to be notified.
alert('this was received on foreground');
}
});
答案 0 :(得分:1)
您应该使用箭头功能
FCMPlugin.onNotification((data) => {
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
alert('data was tapped');
this.tab.select(2);
} else {
//Notification was received in foreground. Maybe the user needs to be notified.
alert('this was received on foreground');
}
});
通过使用箭头函数,this
关键字仍然引用了this.tab
属性所在的组件代码。