我正在使用ionic-framework / cordova来构建我的应用程序.
我安装了这个插件cordova-plugin-background-mode,用于在后台模式下工作.
问:但是现在我怎样才能完成在后台每30分钟重复一次的任务?
你知道另一个插件吗?
谢谢
解决方法:
根据您使用的存储库,代码必须如下所示:
// 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);
原文地址:https://codeday.me/bug/20190628/1315537.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。