background does not work and neither does error

0

Good day I have a function that runs in the constructor and I activate it with

background:
  enviarDatingos(nMinuto){
    //let nDuracion = 1000*60*nMinuto;
    let nDuracion = 1000*nMinuto;

    //console.log(this.backgroundMode.enable());
    // Empezamos a enviar dato de acuerdo al parametro nMinutos
    setInterval(() => {
       //Aqui ejecutamos el servicio
       //console.log(this.contador);
      this.backgroundMode.enable();
       this.contador++;
    },nDuracion);
  }

Then I have another one to stop:

parar(){

    this.backgroundMode.disable();

  }

In the browser does not work for cordova, installed in the device does not work either, no error, someone knows why does not that native library work?

    
asked by joselo 07.11.2018 в 14:17
source

1 answer

0

I could solve it with the following methods and using setInterval:

count:number = 0;
 counter:number;
 start(){
        if (this.counter) clearInterval(this.counter);
    this.counter = setInterval(() => {
      //acas se ejecuta el servicio 
       this.count++;
       console.log(this.count);
      },2000);
 }
stop(){
if (this.counter) clearInterval(this.counter);
    this.count = 0;
}

And this is implemented in the constructor and in the following functions of the homepage:

ionViewWillLeave() {
    this.stop();

  }
  ionViewWillEnter() {
   this.start();
  }
    
answered by 07.11.2018 в 16:59