How could you run a process like a daemon in linux, that is to say a process in the background, as you would do, try with BackgroundMode when you start the application and nothing, as you would.
How could you run a process like a daemon in linux, that is to say a process in the background, as you would do, try with BackgroundMode when you start the application and nothing, as you would.
I was able to solve the problem with the following created service that should be called at app.component.ts:
I was able to solve the problem with the following service created in ionic 4:
import { Injectable } from '@angular/core';
import { BackgroundMode } from '@ionic-native/background-mode/ngx';
import { Platform } from '@ionic/angular';
@Injectable({
providedIn: 'root'
})
export class EnviarService {
cont:number = 0;
constructor(private backgroundMode: BackgroundMode,public plt:Platform) {
}
enviarDatosServidor(nMinutos:number){
this.plt.ready().then(() => {
this.backgroundMode.enable();
// Empezamos a enviar dato de acuerdo al parametro nMinutos
setInterval(() => {
//Aqui ejecutamos el servicio
console.log(this.cont);
this.cont++;
},nMinutos*1000);
});
}
}
And we call it on app.component.ts:
import {Component} from '@ angular / core';
import {Platform} from '@ ionic / angular'; import {SplashScreen} from '@ ionic-native / splash-screen / ngx'; import {StatusBar} from '@ ionic-native / status-bar / ngx';
import {SendService} from './enviar.service';
@Component ({ selector: 'app-root', templateUrl: 'app.component.html' }) export class AppComponent { builder( private platform: Platform, private splashScreen: SplashScreen, private statusBar: StatusBar, public _enviarService: SendService ) { this.initializeApp (); }
initializeApp () { this.platform.ready (). then (() = > { this.statusBar.styleDefault (); this.splashScreen.hide (); this._sendService.sendServerData (4); }); } }