react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Background location stop and restart
Your Environment
- Plugin version: 4.8.1
- Platform: Android
- OS version: 11
- Device manufacturer / model: Xiaomi
- React Native version (
react-native -v): 0.67.3 - Plugin config
const Config = {
reset: true,
debug: false,
logLevel: BackgroundGeolocation.LOG_LEVEL_OFF,
logMaxDays: 7,
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 0 ,
useSignificantChangesOnly: false,
disableElasticity: false,
elasticityMultiplier: 1,
enableTimestampMeta: false,
desiredOdometerAccuracy: 100,
stopOnStationary: false,
disableMotionActivityUpdates: false,
locationUpdateInterval: 3000,
fastestLocationUpdateInterval: 3000,
deferTime: 0,
allowIdenticalLocations: true,
stationaryRadius: 25,
preventSuspend: false,
locationAuthorizationRequest: 'WhenInUse', //then set this to 'always' for ios
locationAuthorizationAlert: {
titleWhenNotEnabled:
"Le service de localisation n'est pas configurer correctement",
titleWhenOff: "Le service de Localisation n'est pas activé",
instructions:
'Vous devez parametrer votre position sur "toujours" afin qu\'Aptimiz soit en mesure de fonctionner correctement',
cancelButton: 'Annuler',
settingsButton: 'Parametre',
},
backgroundPermissionRationale: {
title:
'Autorisez {applicationName} a accèder a votre position en arrière plan?',
message:
"Cette application collecte les informations de localisation pour permettre de mesurer votre temps de travail même lorsque l'application est fermée ou non utilisée. La collecte d'information s'arrêtera si vous éteignez le bouton de l'application.",
positiveAction: 'Changez à {backgroundPermissionOptionLabel}',
negativeAction: 'Annuler',
},
notification: {
title: "Aptimiz est en cours d'utilisation",
text: 'Aptimiz utilise votre position',
largeIcon: 'mipmap-xxxhdpi/ic_launcher.png',
smallIcon: 'mipmap-hdpi/ic_launcher.png',
},
stopTimeout: 3,
disableStopDetection: false,
pausesLocationUpdatesAutomatically: false,
stopOnTerminate: false,
startOnBoot: true,
heartbeatInterval: 70,
foregroundService: true,
forceReloadOnBoot:true,
forceReloadOnMotionChange: false,
forceReloadOnLocationChange: false,
forceReloadOnGeofence: false,
forceReloadOnHeartbeat: false,
enableHeadless: true,
httpTimeout: 30000,
batchSync: true,
autoSync: true,
disableAutoSyncOnCellular: true,
autoSyncThreshold: 500,
maxBatchSize: -1,
maxRecordsToPersist: -1,
maxDaysToPersist: 365 * 100,
disableLocationAuthorizationAlert: false,
};
Expected Behavior
Getting locations saved when the app is in headless mode
Actual Behavior
Some time the headless does not seems to save locations.
Steps to Reproduce
let HeadlessTask = async event => {
let params = event.params;
console.log('[BackgroundGeolocation HeadlessTask] -', event.name, params);
switch (event.name) {
case 'heartbeat':
// Use await for async tasks
let location = await getCurrentPosition();
console.log(
'[BackgroundGeolocation HeadlessTask] - getCurrentPosition:',
location,
);
break;
}
};
let getCurrentPosition = () => {
return new Promise(resolve => {
BackgroundGeolocation.getCurrentPosition(
{
samples: 3,
desiredAccuracy: 15,
persist: true,
maximumAge: 0,
},
location => {
resolve(location);
},
error => {
resolve(error);
},
);
});
};
Context
I'dont understand why the app stop recording locations and seems to restart for like 2 hours
Debug logs
Logs
[ [angèle.log](https://github.com/transistorsoft/react-native-background-geolocation/files/9696233/angele.log) ](url) ``` ```
locationAuthorizationRequest: 'WhenInUse'
you cannot .stop() and restart the plugin in background / headless with WhenInUse permission.
Also, you don’t need to wrap your own custom .getCurrentPosition method in a Promise — the plug-in’s own .getCurrentPosition (as well as almost every method) already returns a Promise. You’re wrapping a Promise around a Promise.
Thanks for the help with the Promise. But for some of my users, the BackgroundGeolocation.getCurrentPosition doesnt seems to run and restart on its own. But I'm not sure how to interpret these logs
angèle.log
Here is the Javascript source for the plugin's own .getCurrentPosition. Wrapping a Promise around a Promise is pointless.
Have you noticed this error in your logs? The OS is not going to allow you to fetch a location if the foreground-service is unable to build its required notification.
10-02 18:11:43.209 WARN [ForegroundNotification buildDefaultLayout] Failed to find notificationLargeIcon: mipmap-xxxhdpi/ic_launcher.png
notification: {
title: "Aptimiz est en cours d'utilisation",
text: 'Aptimiz utilise votre position',
largeIcon: 'mipmap-xxxhdpi/ic_launcher.png',
smallIcon: 'mipmap-hdpi/ic_launcher.png',
},
And this path doesn't point to android/app/src/res/mipmap-xxxhdpi/ic_launcher.png ?
See api docs Notification.largeIcon
And this error explain why it stop working and restart on its own ?
And this error explain why it stop working and restart on its own ?
I have no idea.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.