反应本机后台作业调度程序

问题描述 投票:0回答:1

我需要为Background job schedule找到解决方案。我的目的是每15分钟将latitudelongitude发送到我的后端。实现此功能的最佳方法是什么?

android react-native
1个回答
1
投票

几个月前我有确切的规格,我用2种方法结束。

虽然我的应用程序需要主动跟踪并将Latlong对象分配到我的后端,只要有新的latlong对象进入,您可以寻找的最佳选项之一是HeadlessJS,需要一些本机编码。

我的解决方案

所有Javascript执行都在后台线程上进行

将业务逻辑与UI线程分开,并将它们存储在redux中。只要应用程序处于活动状态,就可以每n分钟发送一次动作。确保在“功能”面板中打开背景模式(适用于iOS)。

我尝试过的另一种选择

BackgroundTimer允许您每n分钟执行一个特定的片段。例如,

export const watchGPSPositionsAtInterval = function(
  dispatchNewPositionFunction,
  dispatch
) {
  let intervalId = BackgroundTimer.setInterval(() => {
    navigator.geolocation.getCurrentPosition(
      pos => {
        if (pos <= MIN_ACCURACY) {
          dispatchNewPositionFunction(pos, dispatch);
        }
      },
      error => {
        console.log(error);
      },
      {
        enableHighAccuracy: true,
        timeout,
        maximumAge
      }
    );
  }, TIME_INTERVAL);
  return intervalId;
};
© www.soinside.com 2019 - 2024. All rights reserved.