12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import * as TaskManager from 'expo-task-manager';
- import * as Location from 'expo-location';
- import axios from 'axios';
- import { storage, StoreType } from 'src/storage';
- import { Platform } from 'react-native';
- import { API_URL } from 'src/constants';
- import { API } from 'src/types';
- const LOCATION_TASK_NAME = 'BACKGROUND_LOCATION_TASK';
- export const startBackgroundLocationUpdates = async () => {
- const hasStarted = await Location.hasStartedLocationUpdatesAsync(LOCATION_TASK_NAME);
- if (hasStarted) {
- console.log('[BackgroundLocation] Already started...');
- return;
- }
- await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
- accuracy: Location.Accuracy.Highest,
-
- timeInterval: 10 * 60 * 1000,
- showsBackgroundLocationIndicator: false,
- pausesUpdatesAutomatically: false,
-
- foregroundService: {
- notificationTitle: 'NomadMania tracking your location',
- notificationBody: 'Location is used in background every 10 minutes.',
- notificationColor: '#0F3F4F'
- },
-
- activityType: Location.ActivityType.Other
- });
- console.log('[BackgroundLocation] Started task');
- };
- export const stopBackgroundLocationUpdates = async () => {
- const hasStarted = await Location.hasStartedLocationUpdatesAsync(LOCATION_TASK_NAME);
- if (hasStarted) {
- await Location.stopLocationUpdatesAsync(LOCATION_TASK_NAME);
- console.log('[BackgroundLocation] Stopped task');
- }
- };
|