android - 收到推送通知后我的页面打不开
问题描述
在我的 ionic 应用程序中,我需要在收到推送通知后打开特定页面。
我正在 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');
}
}
});
解决方案
推荐阅读
- promise - 从附加到 Suitelet 的客户端脚本中设置现有记录的子列表字段
- kotlin - 在注解处理阶段获取kotlin fun参数的默认值
- amazon-s3 - 有没有办法在对我的 S3 存储服务器的请求中指定图像尺寸?
- php - 如果我经常实例化它们,只使用属性类会更好吗?
- newline - 如何让 Atom 停止添加这些新行
- sql - 每月第一天至上周六
- angular - 将 Reduce 数组映射到字符串
- javascript - 如何在firestore中以离线方式阅读文档并以(在线和离线)方式写入?
- scala - 强制 alpakka kafka 消费者在反序列化错误时显示错误消息
- c# - 尝试重现 MS-Office 的文件加密时得到错误的 'encryptedVerifierHashInput' 值