[离子]间隔如何在后台工作 [英] [ionic]How does interval work in background

查看:118
本文介绍了[离子]间隔如何在后台工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作间隔运行功能获取wifi信息并发送到数据库
它在打开应用程序时工作正常。
插件 - 后台模式工作和显示文本Myapp1在后台运行
但功能不起作用。

I am making interval that run function get wifi info and send to database it's work fine when open app . plugin-background-mode working and show text "Myapp1 running in background" but function doesn't work.

app.js

 .run(function($ionicPlatform, $ionicHistory){
$ionicPlatform.ready(function () { ...

    cordova.plugins.backgroundMode.enable(); //enable  background mode as default 
        cordova.plugins.backgroundMode.setDefaults({ //Modify the display information
        title:  'Myapp1',
        text:   'Myapp1 running in background'
    })
})

controller.js

controller.js

.controller('DashCtrl',function(....) {

     $scope.$on('$ionicView.enter', function() {


      $scope.getWifiInfo  = function(){...}

         .
         .
         .

         $interval($scope.getWifiInfo, 20000);

         .
         .
         .

  });


});

我试图将函数放入

cordova.plugins.backgroundMode.onactivate = function () {}

但仍然无效

推荐答案

至少进行一次函数调用:

make the function call at least one time:

.controller('DashCtrl',function($interval,$ionicView) {
 $scope.$on('$ionicView.enter', function() {
 $interval($scope.getWifiInfo, 20000);
 });
 $scope.getWifiInfo  = function(){
 /* Your Code */
}
});

这篇关于[离子]间隔如何在后台工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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