diff --git a/src/screens/RecordingScreen.tsx b/src/screens/RecordingScreen.tsx index 7b2bb1b..164aa47 100644 --- a/src/screens/RecordingScreen.tsx +++ b/src/screens/RecordingScreen.tsx @@ -6,7 +6,7 @@ import { activateKeepAwakeAsync, deactivateKeepAwake } from 'expo-keep-awake'; import { Map, Camera, GeoJSONSource, Layer, UserLocation } from '@maplibre/maplibre-react-native'; import type { LineLayerStyle } from '@maplibre/maplibre-react-native'; import { useRecordingStore } from '../store/recording'; -import { startGpsRecording, stopGpsRecording, requestLocationPermissions } from '../services/gps'; +import { startGpsRecording, stopGpsRecording, requestLocationPermissions, requestForegroundLocation } from '../services/gps'; import { RootStackParamList } from '../types'; import { colors } from '../theme'; import { useTheme } from '../ThemeContext'; @@ -27,6 +27,10 @@ export function RecordingScreen() { return () => { if (intervalRef.current) clearInterval(intervalRef.current); }; }, []); + useEffect(() => { + requestForegroundLocation(); + }, []); + useEffect(() => { if (keepAwake && status === 'recording') activateKeepAwakeAsync(); else deactivateKeepAwake(); @@ -94,7 +98,7 @@ export function RecordingScreen() { diff --git a/src/services/gps.ts b/src/services/gps.ts index 71d0c0a..8a23997 100644 --- a/src/services/gps.ts +++ b/src/services/gps.ts @@ -55,6 +55,11 @@ async function maybeNotifyKm(distanceMeters: number): Promise { }); } +export async function requestForegroundLocation(): Promise { + const { status } = await Location.requestForegroundPermissionsAsync(); + return status === 'granted'; +} + export async function requestLocationPermissions(): Promise { const { status: fg } = await Location.requestForegroundPermissionsAsync(); if (fg !== 'granted') return false;