Reputation: 161
I have a problem in my ionic apps, it must update data from database server to sqlite every 30 minutes I need an example about how to make a job scheduller that run every 30 minutes
Is jobscheduller still works even if I use IOS?
Upvotes: 0
Views: 1206
Reputation: 4013
You can use the background mode plugin, here you can find the plugin
After that you have finished with the installation of the plugin you can enable the background mode, it means that the app don't will die until you disable the background mode again.
Disclaimer: this solution can be expensive in terms of battery usage
app.component.ts
import {Component} from '@angular/core';
import {Platform} from 'ionic-angular';
import {BackgroundMode} from '@ionic-native/background-mode';
@Component({
templateUrl: 'app.component.html'
})
export class AppComponent {
constructor(private plt: Platform, private backgroundMode: BackgroundMode) {
this.plt.ready().then(() => {
this.backgroundMode.enable();
// start an interval with a delay of 30 min
setInterval(() => {
console.log('background on'):
}, 30 * 60000);
});
}
}
This is just a sample code, remember to handle how you will turn off the background mode and dispose the interval.
Upvotes: 1