首页 > 解决方案 > 收到推送通知后我的页面打不开

问题描述

在我的 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');
    }
  }
});

标签: androidpush-notificationionic3

解决方案


推荐阅读