Reputation: 41
I'm using ionic-framework
/ cordova
for building my app.
I've installed this plugin cordova-plugin-background-mode for working in background mode.
Q: But now how can I do a task that repeats every 30 minutes in background?
Do you know another plugin that does this?
Thanks
Upvotes: 4
Views: 8193
Reputation: 183
You can use $timeout
and $interval
for this task with centain period of time
Upvotes: -2
Reputation: 8062
According to the repository that you used the code must look like this:
// Run when the device is ready
document.addEventListener('deviceready', function () {
// Android customization
// To indicate that the app is executing tasks in background and being paused would disrupt the user.
// The plug-in has to create a notification while in background - like a download progress bar.
cordova.plugins.backgroundMode.setDefaults({
title: 'TheTitleOfYourProcess',
text: 'Executing background tasks.'
});
// Enable background mode
cordova.plugins.backgroundMode.enable();
// Called when background mode has been activated
cordova.plugins.backgroundMode.onactivate = function () {
// Set an interval of 30 minutes (1800000 milliseconds)
setInterval(function () {
// The code that you want to run repeatedly
}, 1800000);
}
}, false);
Upvotes: 8