从Json URL获取本地通知

问题描述 投票:0回答:2

l使用数据json api .l想要在用户点击铃声时进行航班时刻表详细信息,他会获得有关航班状态的通知,如果她到达或延迟或着陆。我安装了Local Notifications native 用于离子。

enter image description here

home.ts持有数据json url

  constructor(private http: HTTP, private localNotifications: LocalNotifications) {

 this.getdata()
   }


    async getdata() {

     const loading = await this.loadingController.create({
       message: 'Loading'
     });
     await loading.present();

      this.http.get('/airport.json?code=bs', {}, {})
      .then(data => {

         this.test = JSON.parse(data.data);
         const parsed = JSON.parse(data.data);
        this.yestrday = parsed.result.response.airport.pluginData.schedule.arrivals.data;
         loading.dismiss()



       }), err=>{
         this.test =err
        loading.dismiss()
     } 

 }
 navigate(item,aiprot,time,type,status,airline,logo){
this.nav.navigateForward(`/flightserachdetails/${item}/${aiprot}/${time}/${type}/${status}/${airline}/${logo}`);
 }
 }

页面包含航班详情的数据

    export class FlightserachdetailsPage {

      public flight : any

      callsign =null
      airport = null 
      status = null
      aircraft = null
      airline = null
      time = null
      logo = null
      constructor(private http: HTTP, public loadingController: LoadingController,private localNotifications: LocalNotifications,
                   private nav : NavController,private activatedRoute : ActivatedRoute) {
                    this.activatedRoute.params.subscribe((params) => {
                      this.callsign = params['callsign'];
                      this.airport = params['airport'];
                      this.time = params['time'];
                      this.aircraft = params['aircraft'];
                      this.status = params['status'];
                      this.airline = params['airline'];
                      this.logo = params['logo'];



                    });

       }

   AlertFlight(){
    if (this.status=='Landed') {
      this.localNotifications.schedule({
        title: 'My first notification',
        text: 'flight is landed',
        foreground: true

      });
    }
  }
    }

HTML

<button item-right clear (click)="AlertFlight()">
angular notifications ionic4
2个回答
0
投票

你在AlertFlight()方法中检查的条件是this.status=='landed',但你在图像中显示的状态是'Landed'。所以改变这样的条件

   AlertFlight(){
    if (this.status=='Landed') {
      this.localNotifications.schedule({
        title: 'My first notification',
        text: 'flight is landed',
        foreground: true

      });
    }
  }

0
投票

这是普通js中的一个例子,它在角度上的工作方式相同。

<!DOCTYPE html>
<html>
  <head>
    <script src="https://npmcdn.com/@reactivex/[email protected]/dist/global/Rx.umd.js"></script>
    <script>
      let subject = new Rx.Subject();
      let status = "";
      Rx.Observable.of("").subscribe(x => {
        setTimeout(() => {
          status = "departed";
          subject.next("status");
        }, 1000),
          setTimeout(() => {
            status = "enroute";
            subject.next(status);
          }, 10000),
          setTimeout(() => {
            status = "landed";
            subject.next(status);
          }, 10000);
      });

      subject.subscribe(x => {
        AlertFlight();
      });
      function AlertFlight() {
        if (status == "landed") {
          console.log("landed alert");
        }
      }
    </script>
    <title>Page Title</title>
  </head>
  <body></body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.