重复背景任务离子框架 [英] Repeatedly background task ionic framework

查看:118
本文介绍了重复背景任务离子框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ionic-framework / cordova 建立我的应用程式。
我已安装此插件 cordova-plugin-background-mode 用于在后台模式下工作。

I'm using ionic-framework / cordova for building my app. I've installed this plugin cordova-plugin-background-mode for working in background mode.

问:但现在如何在后台每隔30分钟重复一次任务?

Q: But now how can I do a task that repeats every 30 minutes in background?

您知道另一个插件吗?

感谢

推荐答案

根据您使用的存储库,代码必须如下所示:

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);

这篇关于重复背景任务离子框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆