开发者

titanium-mobile scheduled task on iphone/android?

开发者 https://www.devze.com 2023-04-06 16:40 出处:网络
I\'d like to and app every 6 hours or every 12 hours to get开发者_StackOverflow updates from a webserver

I'd like to and app every 6 hours or every 12 hours to get开发者_StackOverflow updates from a webserver

I know this is possible in native android using the alarmmanager. Can I do this for both android and iphone in titanium-mobile?


there a several possibilities to implement that feature. you can google for a push service. another way is to calculate the interval. i would save the installation date and check for the difference moduls 6.

need_to_update = function(installed_time){
  /* current time */
  var current_date = new Date();
  var current_hour = current_date.getHours();

  /* check diff */
  var installed_hour = installed_time.getHours();
  var diff = Math.abs(installed_hour-current_hour);

  /* check interval - here 6 hour interval*/
  var mod = diff % 6;

  /* return result */
  return mod == 0;
}

example: installed_hour = 18; current_hour = 20; diff = 2; mod = 2; returns false;

example two: installed_hour = 4; current_hour = 16; diff = 12; mod = 0; returns true;

0

精彩评论

暂无评论...
验证码 换一张
取 消