首页 > 解决方案 > 为什么世博会后台位置在 5 分钟后停止发送位置?

问题描述

我在 App.js 中定义了任务,一切正常!但 5 分钟后它停止发送位置,我不知道为什么。我正在使用这个包:https ://docs.expo.io/versions/latest/sdk/location/#background-location-methods

TaskManager.defineTask(LOCATION_TASK_NAME, async ({ data, error }) => {

  console.log("Esta entrando al task")
    if (error) {
        console.log(error)
      // Error occurred - check `error.message` for more details.
      return;
    }
    if (data) {
      const { locations } = data;
  

      let getLastTime = await AsyncStorage.getItem('lastTime');
 
      if(getLastTime){

        let timeInterval = moment(new Date()).diff(getLastTime,'seconds')

        if(timeInterval<=10) {
          return
        }
        
 
      }

     await LocationAPI.sendCurrentLocation(locations[0].coords).then(async res=>{
        await AsyncStorage.setItem('lastTime',  new Date().toString())
    

      }).catch(err=>{

      console.log(err)
      console.log("en el task")
      })


   
      // do something with the locations captured in the background
    }
  });

标签: react-nativeexpo

解决方案


推荐阅读