开发者

titanium-mobile scheduled task on iphone/android?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜