diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2024-10-20 22:23:59 +0200 | 
|---|---|---|
| committer | Santo Cariotti <santo@dcariotti.me> | 2024-10-20 22:23:59 +0200 | 
| commit | 0c5181056d0977bbb63e34df941a3665a65a50b4 (patch) | |
| tree | ac3c07a25e824caf7f941074bd69d7fbc33b0362 /app/(tabs)/index.tsx | |
| parent | 7c36badf769a3f6e54855dd7f03d25af5434762c (diff) | |
New notification fields
Diffstat (limited to 'app/(tabs)/index.tsx')
| -rw-r--r-- | app/(tabs)/index.tsx | 25 | 
1 files changed, 17 insertions, 8 deletions
diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index 8e52ee1..da967c7 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -37,6 +37,7 @@ TaskManager.defineTask(LOCATION_TASK_NAME, async ({ data, error }) => {    if (data) {      const { locations } = data;      console.log("Received new locations:", locations); +    updateLocation(location.coords, location.coords.speed);      // Process the locations here    }  }); @@ -346,7 +347,7 @@ export default function HomeScreen() {          movingActivity = "IN_VEHICLE";        } -      await fetch( +      const response = await fetch(          `${process.env.EXPO_PUBLIC_ALERTD_URL}`,          {            method: "POST", @@ -362,6 +363,10 @@ export default function HomeScreen() {            }),          },        ); +      const data = await response.json(); +      if (response.status != 200) { +        console.error(data) +      }      } catch (err) {        console.error("Error on updating position");      } @@ -382,7 +387,7 @@ export default function HomeScreen() {                "Content-Type": "application/json",              },              body: JSON.stringify({ -              query: `{ notifications(seen: false) { id, createdAt, level, alert { id, text1 text2 text3 } position { movingActivity } } }`, +              query: `{ notifications(seen: false) { id, createdAt, level, alert { id, text1 text2 text3 }, movingActivity } }`,              }),            },          ); @@ -440,15 +445,20 @@ export default function HomeScreen() {        try {          const { status } = await Location.requestForegroundPermissionsAsync();          if (status === "granted") { -          setInterval(async () => { -            const location = await Location.getCurrentPositionAsync({}); -            updateLocation(location.coords, location.coords.speed); -          }, 2000); +          Location.watchPositionAsync( +            { +              accuracy: Location.Accuracy.Balanced, +              distanceInterval: 10, +            }, +            location => { +              updateLocation(location.coords, location.coords.speed); +            } +          )            await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {              accuracy: Location.Accuracy.Balanced, // ~100 meters of precision              distanceInterval: 10, // Send data only if they moved of >=10 meters -            deferredUpdatesInterval: 1000, +            deferredUpdatesInterval: 10000,              showsBackgroundLocationIndicator: true,              foregroundService: {                notificationTitle: "CAS4 Location Tracking", @@ -464,7 +474,6 @@ export default function HomeScreen() {          console.error("Error starting background location updates:", error);        }      }; -      startBackgroundLocationTracking();    }, []);  |