【问题标题】:Define which page to open when clicking on Push Notification in Ionic 2定义在 Ionic 2 中单击推送通知时要打开的页面
【发布时间】:2017-07-11 17:31:34
【问题描述】:

我的 Ionic 2 应用程序已经收到推送通知。当点击通知(应用关闭)时,应用打开并显示根页面。

如何定义另一个页面以在单击通知后打开应用程序时显示?

理想情况下,我会在推送通知中传递另一个名为“页面”的字段参数,我可以在其中定义要打开的页面。

现在我在我的应用中处理通知所做的只是:

this.push.rx.notification()
      .subscribe((msg) => {
        alert(msg.title + ': ' + msg.text);
      });

【问题讨论】:

    标签: ionic-framework push-notification ionic2


    【解决方案1】:

    我正在使用 FCM 本机,这对我有用,请在下面找到一个示例 - 我将 notificationType 设置为 push_chat 然后转到 ChatPage 如果未设置 push_chat 则转到主页

    import { FCM } from '@ionic-native/fcm';
    
    constructor(private fcm: FCM) {}
    
    ...
    
       this.fcm.onNotification()
          .subscribe((msg) => {
          let messageData = JSON.parse(msg.messageData);
          let ref_this = this;
          if (msg.wasTapped) {
            if(msg.notificationType == 'push_chat') {
                ref_this.nav.setRoot(ChatPage);
            else {
                ref_this.nav.setRoot(Home);
                break;
            }
           });
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多