Closed mcottingham closed 1 week ago
react-native -v
Plugin config
/* _layout.js */ const activityListener = useRef(); const locationListener = useRef(); const heartbeatListener = useRef(); const geofenceListener = useRef(); const motionListener = useRef(); const [bgGeolocationReady, setBGGeolocationReady] = useState(false); useEffect(() => { activityListener.current = BackgroundGeolocation.onActivityChange(event => store.dispatch(setStatus({ activity: event.activity, activityConfidence: event.confidence }))); geofenceListener.current = BackgroundGeolocation.onGeofencesChange(event => console.log("Geofence change", event)); motionListener.current = BackgroundGeolocation.onMotionChange(event => store.dispatch(setStatus({ motion: event.isMoving ? 'MOVING' : 'STOPPED' }))) locationListener.current = BackgroundGeolocation.onLocation(onLocation); heartbeatListener.current = BackgroundGeolocation.onHeartbeat(async (event) => { store.dispatch(setStatus({ heartbeat: moment(event.location?.timestamp).format("hh:mm:ss") })) await onLocation() }); BackgroundGeolocation.ready({ //Debug debug: false, logLevel: BackgroundGeolocation.LOG_LEVEL_ERROR, //GeoLocation desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, preventSuspend: true, stationaryRadius: 25, heartbeatInterval: 60, showsBackgroundLocationIndicator: true, //Application startOnBoot: true, stopOnTerminate: false, enableHeadless: true, //Notification foregroundService: true, notification: { title: "Be Safe - On Shift", text: "Be Safe is monitoring your location, keeping you safe.", color: theme.palette.green, sticky: true, }, locationAuthorizationRequest: "Always", backgroundPermissionRationale: { title: "Allow Be Safe - Work Alone to access this device's location in the background?", message: "In order to track your activity in the background, please enable Allow all the time location permission", positiveAction: "Change to Allow all the time", negativeAction: "Cancel", } }).then(state => { console.log("Initialized successfully", "enabled", state.enabled); setBGGeolocationReady(true); }).catch(ex => console.log("Failed to ready geolocation", ex)); return () => { (async () => { try { console.log("cleaning up"); await activityListener.current?.remove(); await locationListener.current?.remove(); await heartbeatListener.current?.remove(); await motionListener.current?.remove(); await geofenceListener.current?.remove(); console.log("clean up complete"); } catch (ex) { console.log("failed to clean up", ex); } })() }; }, []);
### Android headless task registration ```javascript /* _layout.js */ BackgroundGeolocation.registerHeadlessTask(async (event) => { if (event.name === 'heartbeat') { await onLocation(); } });
/* _layout.js */ const onLocation = async (l) => { let taskId = await BackgroundGeolocation.startBackgroundTask(); try { let location = l; const { attributes: { email: userEmail } } = await Auth.currentAuthenticatedUser(); if (!location) { location = await BackgroundGeolocation.getCurrentPosition({ desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION, samples: 3 }) } await store.dispatch(updateStatus({ email: userEmail, location: toAWSLocation(location.coords), timestamp: location.timestamp })) } catch (ex) { console.log("Failed to process location", ex); } finally { await BackgroundGeolocation.stopBackgroundTask(taskId); } }
We are using expo-router. We have registered / setup the BackgroundGeolocation library inside our main _layout.js file.
No exceptions are being thrown to Sentry.
@christocracy Any thoughts?
Try latest release 4.17.5
4.17.5
Updated, we'll see how this version works. Thank you.
Your Environment
react-native -v
): 0.74.5Plugin config
onLocation handler
We are using expo-router. We have registered / setup the BackgroundGeolocation library inside our main _layout.js file.
Expected Behavior
Actual Behavior
No exceptions are being thrown to Sentry.