在我的离子应用程序中,我需要在收到推送通知后打开特定页面。
我正在Android Studio模拟器中对其进行测试,并显示了一堆控制台日志,这些日志证明push.on('notification')。subscribe事件肯定是使用navCtrl.push触发页面的(我已经尝试过navCtrl.setRoot),并且ngOnInit会像往常一样做所有事情,并将其放置到代码末尾。
问题是在那之后,该页面没有显示。
我可以在Android控制台日志中看到以下消息,但我真的不知道这意味着什么:
D/SystemWebChromeClient: ng:///AppModule/ShiftDetailsPage.ngfactory.js: Line 563 : ERROR
I/chromium: [INFO:CONSOLE(563)] "ERROR", source: ng:///AppModule/ShiftDetailsPage.ngfactory.js (563)
但是它们出现在ShiftDetailsPage中ngOnInit输出的所有控制台日志消息之前,所以我想它们并不意味着加载页面时出现问题。
出现的另一件事是:
Cannot read property 'controls' of undefined.
在应用程序中。
我到处搜索有类似问题的人,但是我所能找到的只是关于如何接收通知的描述,但是对于如何从事件中触发页面没有帮助。
我是否应该使用除navCtrl.push之外的其他方式,或者这是正确的方式?
任何建议都非常欢迎。
这是push.on订阅中的代码:
push.on('notification').subscribe(async (data: EventResponse) => {
console.log("in notification, data = " + JSON.stringify(data));
if (data.additionalData.shiftId != null
&& data.additionalData.shiftId != ""
&& await this.login.isLoggedIn()
) {
console.log("in notification, shiftId = " + data.additionalData.shiftId);
console.log("in notification, isLoggedIn = " + JSON.stringify(await this.login.isLoggedIn()));
const confirmAlert = this.alertCtrl.create({
title: 'Shift Notification',
message: data.additionalData.shiftId,
buttons: [
{
text: 'Ignore',
role: 'cancel'
},
{
text: 'View',
handler: () => {
console.log("in notification, handler");
this.shiftDetailsProvider.getShiftDetails(data.additionalData.shiftId).then( async shift => {
const userLocation = await this.getUserLocation().then(userLocation => {
console.log("in pushSetup on notification, userLocation = ", userLocation);
return userLocation;
});
this.navCtrl.push(ShiftDetailsPage, {shift: shift, userLocation: userLocation, sourcePage: "notification"});
});
}
},
]
});
confirmAlert.present();
} else {
console.log("in notification, else");
if (data.additionalData.foreground) {
console.log("in notification, foreground");
const confirmAlert = this.alertCtrl.create({
title: 'New Notification',
message: data.message,
buttons: [
{
text: 'Cancel',
role: 'cancel'
},
{
text: 'OK',
handler: () => {
console.log('New notification callback')
}
},
]
});
confirmAlert.present();
if (this.platform.is('ios')) {
console.log("in notification, platform is ios");
push.finish(data.additionalData.notId);
}
} else {
console.log('Push notification clicked from the background');
}
}
});