2016-08-29 56 views
1

我开发了一个使用angularjs的离子应用程序。现在,如果我不关闭我的应用程序,我的应用程序运行良好,但是我的应用程序的功能类似于闹钟,因此即使在用户关闭应用程序后,我也需要从后台触发它。那么我怎么能做到这一点。在背景模式下运行离子应用程序

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

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

+0

我假设你正在某种提醒应用程序的其中显示一些弹出窗口或'在应用notification'您必须配置第一背景使心情,然后在后台调用你的功能 –

+0

是的,它是一种提醒应用程序。那么如何配置背景启用模式? –

回答

0

首先安装这个插件 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); 
+0

感谢您的代码,但我需要把这个作为我的应用程序在angularJs中。所以在我的角码中,我需要放置这些代码的位置? –

+0

你必须在'离子设备就绪'功能中加入这个功能 –

相关问题