离子 2/3 中的一个信号附加数据

Par*_*ari 4 notifications push ionic-framework onesignal ionic2

我正在尝试在我的 ionic 2 应用程序中使用一个信号插件

我已经安装了 Onesignal 并且它工作正常,但我不知道如何使用handleNotificationOpened函数,根本没有文件(没有找到任何文件)

这是我的代码:

this.oneSignal.handleNotificationReceived().subscribe((msg) => {
       // o something when notification is received
      });
Run Code Online (Sandbox Code Playgroud)

但我不知道如何msg用于获取数据。

有什么帮助吗?关联?保护你

Swa*_*twa 5

这是当应用程序从通知启动时将用户重定向到相关页面的方式。

app.component.ts

this.oneSignal.handleNotificationOpened().subscribe((data) => { 
      let payload = data; // getting id and action in additionalData.
      this.redirectToPage(payload);
 });


redirectToPage(data) { 
    let type
    try {
      type = data.notification.payload.additionalData.type;
    } catch (e) {
      console.warn(e);
    }
    switch (type) {
      case 'Followers': {
        this.navController.push(UserProfilePage, { userId: data.notification.payload.additionalData.uid });
        break;
      } case 'comment': {
        this.navController.push(CommentsPage, { id: data.notification.payload.additionalData.pid })
        break;
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)