Cordova调度任务 [英] Cordova scheduling task

查看:276
本文介绍了Cordova调度任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cordova开发移动应用程序(平台:Android,iOS)。



我的应用程序需要ping一个URL来每小时获取数据。我想我的应用程序仍然ping的URL,当它关闭。



我在google搜索,我得到一些插件:


  1. a href =https://github.com/katzer/cordova-plugin-local-notifications =nofollow> https://github.com/katzer/cordova-plugin-local-notifications

  2. https://github.com/katzer/cordova -plugin-background-mode

我需要一个类似第二个插件,但也可以在应用程序关闭时如第一个预定的通知。



有没有像cordova这样的插件?



谢谢

解决方案

我有一些什么相同的问题,我需要选择拉,lng每隔几分钟和计算距离,但背景插件单独couldnt解决它,因为它停止工作时,手机睡觉..所以我有确保手机不会进入睡眠状态。



所以我使用电源管理插件与背景模式插件..它的工作原理。 p>

背景模式插件:
https://github.com/katzer/cordova-plugin-background-mode



电源管理插件
https://github.com/boltex/cordova-plugin-powermanagement

  if(ionic.Platform.isAndroid()){
cordova.plugins.backgroundMode.enable();

window.powerManagement.dim(function(){
console.log('Wakelock acquired');
},function(){
console.log 'failed to get wakelock');
});
window.powerManagement.setReleaseOnPause(false,function(){
console.log('setReleaseOnPause successfully');
},function(){
console.log to set');
});

}


I am developing an mobile application (platform: Android, iOS) with Cordova.

My application needs ping an URL to fetch data every hours. I want my application still ping the URL when it's closed.

I searched in google and I get some of this plugins:

  1. https://github.com/katzer/cordova-plugin-local-notifications
  2. https://github.com/katzer/cordova-plugin-background-mode

I need a plugin like the second one but also work when the application is closed like scheduled notification like the first one.

Is there any plugin like this for cordova? Or it's impossible to do background task like this with cordova.

Thank you

解决方案

I had some what the same issue, i needed to pick lat,lng every few minutes and calcuate the distance, but background plugin alone couldnt solve it, as it stops working when the phone goes to sleep .. so I had to make sure, the phone doesn't go to sleep ..

So i used power management plugin together with Background mode plugin.. and it works well..

Background mode Plugin: https://github.com/katzer/cordova-plugin-background-mode

Power Management Plugin https://github.com/boltex/cordova-plugin-powermanagement

if( ionic.Platform.isAndroid() ){
cordova.plugins.backgroundMode.enable();

window.powerManagement.dim(function() {
console.log('Wakelock acquired');
}, function() {
console.log('Failed to acquire wakelock');
});
window.powerManagement.setReleaseOnPause(false, function() {
console.log('setReleaseOnPause successfully');
 }, function() {
console.log('Failed to set');
 });

}

这篇关于Cordova调度任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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