ionic 收到推送后跳转页面

1. 在 app.component.ts 中注册推送接受事件

2. 1 private modalCtrl: ModalController, 2 private appCtrl: App, 3 private ionicApp: IonicApp, 

3.在接受到推送的事件中调用如下方法

  1       // alert("notification:" + JSON.stringify(notification))
  2       console.log("notification:" + JSON.stringify(notification))
  3       // if (this.platform.is("android") || this.platform.is("ios")) {
  4       let additionalData = notification.additionalData
  5       let message = notification.message
  6       //this.nav.popToRoot()
  7       //如果时 coldstart :true,
  8       if (additionalData["coldstart"] == true) {
  9         console.log("coldstart =true")
 10         //alert("coldstart =true")
 11         this.pushMessagePushPage(additionalData)
 12 
 13       } else {
 14 
 15 
 16 
 17         //如果是foreground=true 提示用户是否跳转,否则直接跳转
 18         if (additionalData["foreground"] == false) {
 19           console.log("foreground =false")
 20           let that=this
 21           //然后如果有其他model,页面,关闭掉,
 22           let activePortal = this.ionicApp._modalPortal.getActive() || this.ionicApp._overlayPortal.getActive();
 23           if (activePortal) {
 24             let that2=that
 25             //其他的关闭
 26             activePortal.dismiss().then(() => {
 27               let that3=that2
 28               that2.appCtrl.getActiveNav().popToRoot().then(() => {
 29                 that3.pushMessagePushPage(additionalData);
 30               })
 31             }).catch(() => {
 32 
 33             });
 34             activePortal.onDidDismiss(() => {
 35 
 36             });
 37             //  return;
 38           } else {
 39             
 40             this.appCtrl.getActiveNav().popToRoot().then(() => {
 41               that.pushMessagePushPage(additionalData);
 42             })
 43           }
 44 
 45 
 46         } else {
 47           console.log("foreground =true")
 48           //您有新的审批信息,是否查看
 49           const confirm = this.alertCtrl.create({
 50             title: 'Approval',
 51           //  message: message + "<br><span style='color:red;'>。</span>",
 52           message: message ,
 53             buttons: [
 54               {
 55                 text: '取消',
 56                 handler: () => {
 57                   console.log('Disagree clicked');
 58                 }
 59               },
 60               {
 61                 text: '查看',
 62                 handler: () => {
 63                   // this.gv.showAlert("当前页面是:"+this.nav.getActive().component.name)
 64                   //返回根视图
 65                   // this.nav.setRoot(TabsPage);
 66                   //  this.appCtrl.getRootNav().setRoot(TabsPage);
 67                   //  this.pushMessagePushPage(additionalData);
 68                   
 69                  // alert(this.appCtrl.getActiveNav().getActive().name)   
 70 
 71                    let that=this
 72                   //然后如果有其他model,页面,关闭掉,
 73                   let activePortal = this.ionicApp._modalPortal.getActive() || this.ionicApp._overlayPortal.getActive();
 74                   if (activePortal) {
 75                     let that2=that
 76                     //其他的关闭
 77                     activePortal.dismiss().then(() => {
 78                       let that3=that2
 79                       that2.appCtrl.getActiveNav().popToRoot().then(() => {
 80                         that3.pushMessagePushPage(additionalData);
 81                       })
 82                     }).catch(() => {
 83 
 84                     });
 85                     activePortal.onDidDismiss(() => {
 86 
 87                     });
 88                     //  return;
 89                   } else {
 90                     
 91                     this.appCtrl.getActiveNav().popToRoot().then(() => {
 92                       that.pushMessagePushPage(additionalData);
 93                     })
 94                   }
 95 
 96                   console.log('Agree clicked');
 97 
 98 
 99                 }
100               }
101             ]
102           });
103           confirm.present();
104         }
105 
106       }

4.页面跳转的方法

1 pushMessagePushPage(additionalData) {
2    this.appCtrl.getActiveNav().push(ApprovalPage, additionalData)
3 }

猜你喜欢

转载自www.cnblogs.com/hbyjw/p/9469486.html