【问题标题】:How to change view after user tap push notification - Firebase - Native Script用户点击推送通知后如何更改视图 - Firebase - 本机脚本
【发布时间】:2020-05-24 17:38:22
【问题描述】:

我试图确保当用户单击推送通知气球时,应用程序会打开并转到特定页面。

我将 Nativescript 与 firebase 一起使用。这是app.component.tns.ts的代码段:

firebase.init({
  showNotificationsWhenInForeground: true,
  onMessageReceivedCallback: (message) => {
    if (message.foreground) {
      alert('app is open');
    } else {
      console.log('app background');
      this.routerExtensions.navigate(["messages"] ); 
    }
  }
})

当应用程序在前台时,会显示警报,当应用程序在后台时,我点击通知,控制台日志会打印出来,但什么也没发生。

更新

当我在后台说应用程序时,这意味着应用程序仍然存在,当点击通知时,应用程序从启动屏幕启动。

【问题讨论】:

  • 当你在后台说应用程序时,应用程序还活着还是被杀死?点击通知会让应用从闪屏开始?

标签: javascript typescript firebase push-notification nativescript


【解决方案1】:

您应该为此使用 firebase.addOnMessageReceivedCallback() 函数。这在官方 github 上提到了 nativescript firebase 项目。

https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/MESSAGING.md

firebase.addOnMessageReceivedCallback((message) => {
    this.zone.run(() => {
        this.router.navigate(['messages']);
      });
  });

【讨论】:

  • 不起作用,没有进入zone.run
【解决方案2】:
  • 你的路由路径好像是相对的["messages"],我觉得应该是绝对的["/messages"]
  • 使用 Angular,您必须在区域内运行导航,firebase 回调在区域外执行。

       this.ngZone.run(() => this.router.navigate(['/messages']))
    

【讨论】:

  • 不起作用,没有进入 zone.run() ,这是进入 app.component ,对吗?
猜你喜欢
  • 1970-01-01
  • 2021-01-20
  • 2015-06-18
  • 1970-01-01
  • 1970-01-01
  • 2023-02-22
  • 1970-01-01
  • 1970-01-01
  • 2017-06-29
相关资源
最近更新 更多