在后台模式下运行ionic app

时间:2016-08-29 19:00:47

标签: angularjs cordova ionic-framework

我使用angularjs开发了一个离子应用程序。现在我的应用程序工作正常,如果我不关闭我的应用程序,但我的应用程序的功能就像一个警报,所以即使用户关闭应用程序后我也需要从后台触发它。那么我怎样才能实现这一点。

我甚至发现了这个 https://github.com/katzer/cordova-plugin-background-mode

但我不确定如何与angularjs一起使用它。或者,如果你知道任何其他方法来实现这一点,那么请分享。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

首先安装此插件 https://github.com/katzer/cordova-plugin-background-mode#examples

然后

document.addEventListener('deviceready', function () {
    // Android customization
    cordova.plugins.backgroundMode.setDefaults({ text:'Doing heavy tasks.'});
    // Enable background mode
    cordova.plugins.backgroundMode.enable();

    // Called when background mode has been activated
    cordova.plugins.backgroundMode.onactivate = function () {
        setTimeout(function () {
            // Modify the currently displayed notification
            cordova.plugins.backgroundMode.configure({
                text:'Running in background for more than 5s now.'
            });
        }, 5000);
    }
}, false);
相关问题