Get local notification from data json url

l have ionic app for flights schedules details using data json api .l want to make when user click on bell he will get notification about the status of flight , if she is arrival or delay or landed . l installed Local Notifications native for ionic .

l did like that but he doesn’t work !

    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()">

Hi @aligassan,

Unfortunately can’t do these checks they way you want, as the code won’t execute when the app is not in the foreground or the screen is off.

You would need to check the data on a server at regular intervals, and then send a push notification when a change happens.

Best,
Rodrigo

Hi sir , thank you for replying . how can l do that ? there is a example code ? you can see below my code …

home.ts holding data json url

   test : any[]
   public yestrday : any ;
 

  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}`);
 }
 }

flight details code

 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

      });
    }
  }
    }

You can check how to use the Push plugin from Ionic Native to receive push notifications from a server here: https://ionicframework.com/docs/native/push/

About the server side, you would have to code the program to check for changes periodically yourself.