Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

Expo background Location not working in background

$
0
0

The background service works perfectly in the foreground but when the app is in the background, stops sending the location updated.

this mostly happens when the app is in production, here more details:

this is the task:

TaskManager.defineTask(LOCATION_TASK_NAME, async ({ data, error }) => {  console.log("Entro a este task")    if (error) {        console.log(error)      // Error occurred - check `error.message` for more details.      return;    }    if (data) {      const { locations } = data;      console.log(locations)      let getLastTime = await AsyncStorage.getItem('lastTime');    console.log(getLastTime)      if(getLastTime){        let timeInterval = moment(new Date()).diff(getLastTime,'seconds')        if(timeInterval<=10) {          return        }        console.log(timeInterval)        console.log("Este es el intervalo")      }     await LocationAPI.sendCurrentLocation(locations[0].coords).then(async res=>{        console.log(res)        console.log("Se envio")        await AsyncStorage.setItem('lastTime',  new Date().toString())      }).catch(err=>{        alert(err.message)      })      // do something with the locations captured in the background    }  });

this is the function that calls this task:

        const { status } = await Location.requestPermissionsAsync();        if (status === "granted") {          await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {            accuracy: Location.Accuracy.BestForNavigation,            showsBackgroundLocationIndicator: true,            activityType: Location.ActivityType.AutomotiveNavigation,            foregroundService: {              notificationTitle: "Tienes una orden activa",              notificationBody: "Entregando pedido...",              notificationColor: "#RRGGBB",            },          });        }

Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>