【问题标题】:Run ionic app in a background mode在后台模式下运行 ionic 应用程序
【发布时间】:2016-08-29 19:00:47
【问题描述】:

我使用 angularjs 开发了一个离子应用程序。现在,如果我不关闭我的应用程序,我的应用程序可以完美运行,但是我的应用程序的功能就像一个警报,所以即使在用户关闭应用程序之后,我也需要从后台触发它。那么我该如何实现呢。

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

但我不确定如何将它与 angularjs 一起使用。或者,如果您知道实现此目的的任何其他方法,请分享。任何帮助将不胜感激。

【问题讨论】:

  • 我假设您正在制作某种提醒应用程序,它会向您显示一些弹出窗口或in app notification,您必须先配置背景启用心情,然后在后台调用您的功能
  • 是的,它是一种提醒应用。那么如何配置后台启用模式呢?

标签: angularjs cordova ionic-framework


【解决方案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);

【讨论】:

  • 谢谢你的代码,但是我需要把它放在哪里,因为我的应用程序在 angularJs 中。那么在我的角度代码中,我需要在哪里放置此代码?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-16
  • 2011-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-10
  • 2011-09-11
相关资源
最近更新 更多