Onclick推送通知时重定向页面 [英] Redirect Page When Onclick Pushnotifications
本文介绍了Onclick推送通知时重定向页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用FCM PLugin Ionic 2
I am using FCM PLugin Ionic 2
我的应用程序组件下方
constructor(public menu1: MenuController,public alertCtrl:AlertController,public platform: Platform,public authservice:Authservice) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();
//Push Notifications
if(typeof(FCMPlugin) !== "undefined")
{
FCMPlugin.getToken(function(t){
console.log("Use this token for sending device specific messages\nToken: " + t);
}, function(e){
console.log("Uh-Oh!\n"+e);
});
FCMPlugin.onNotification(function(d){
if(d.wasTapped){
console.log(d);
var nav:NavController = this.app.getComponent("nav");
this.nav = nav;
nav.setRoot(MycomplaintsPage);
} else {
console.log("Push Notification", d);
console.log("you have new notifications");
}
}, function(msg){
}, function(err){
console.log("Arf, no good mate... " + err);
});
}
}
工作正常,但是单击通知页面"无法重定向.
It's work Perfectly.But Click on Notifications Page cannot redirect.
我收到此错误
未捕获的TypeError:无法读取未定义的属性'getComponent'.
Uncaught TypeError: Cannot read property 'getComponent' of undefined.
如何解决此问题.
请教我, 谢谢
推荐答案
如果您使用常规函数,则this
对象会更改,即它属于该函数而不是该类,因此也未定义this.app
. 箭头功能 ()=>{}
不定义this
,并使用外部this
.
使用箭头函数进行回调
The this
object changes if you use regular functions i.e it belongs to the function not the class so this.app
is nor defined. Arrow functions ()=>{}
doesn't define this
and the outer this
is used.
Use arrow functions for callbacks
FCMPlugin.onNotification((d)=>{
if(d.wasTapped){
console.log(d);
var nav:NavController = this.app.getComponent("nav");
this.nav = nav;
nav.setRoot(MycomplaintsPage);
//...
});
或在通话前设置self=this
并使用self
.
Or set self=this
before the call and use self
.
let self = this.//declare here
FCMPlugin.onNotification(function(d){
if(d.wasTapped){
console.log(d);
var nav:NavController = self.app.getComponent("nav");//use here
this.nav = nav;
nav.setRoot(MycomplaintsPage);
//...
});
这篇关于Onclick推送通知时重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文