We need to use schedules such as 2019-01-15-11:03 2019-01-15-12:03 (generally starts from now and ends in some hours). Sometimes, GPS location services starts after startSchedule. but most times, GPS not started.
Here's codes on starting schedule:
let schedule = this.datePipe.transform(startDate, "yyyy-MM-dd-HH:mm ") + this.datePipe.transform(endDate, "yyyy-MM-dd-HH:mm");
console.log("new schedule " + schedule);
BackgroundGeolocation.setConfig({
schedule: [schedule],
extras: { id: result.id }
}, (cstate) => {
console.log("setConfig success " + JSON.stringify(cstate));
BackgroundGeolocation.startSchedule();
}, (cerror) => {
console.warn("setConfig failed " + JSON.stringify(cerror));
});
Another thing I noticed that I think could be indication of bug. If I register listener on schedule
BackgroundGeolocation.on('schedule', (state) => {
console.log('[schedule] -', state);
});
it will crash within following callback, toJson is undefined. If I remove listener, crash goes away
Api.createScheduleCallback = function (callback) {
return new TSScheduleCallback({
onSchedule: function (event) {
callback(JSON.parse(event.toJson().toString()));
}
});
};
We need to use schedules such as 2019-01-15-11:03 2019-01-15-12:03 (generally starts from now and ends in some hours). Sometimes, GPS location services starts after startSchedule. but most times, GPS not started. Here's codes on starting schedule: let schedule = this.datePipe.transform(startDate, "yyyy-MM-dd-HH:mm ") + this.datePipe.transform(endDate, "yyyy-MM-dd-HH:mm"); console.log("new schedule " + schedule); BackgroundGeolocation.setConfig({ schedule: [schedule], extras: { id: result.id } }, (cstate) => { console.log("setConfig success " + JSON.stringify(cstate)); BackgroundGeolocation.startSchedule(); }, (cerror) => { console.warn("setConfig failed " + JSON.stringify(cerror)); });
in success call back, we get {"activityRecognitionInterval":10000, "allowIdenticalLocations":false, "autoSync":true, "autoSyncThreshold":0, "batchSync":false, "debug":false, "deferTime":0, "desiredAccuracy":-1, "desiredOdometerAccuracy":100, "disableElasticity":false, "disableStopDetection":false, "distanceFilter":5, "elasticityMultiplier":1, "enableHeadless":true, "enableTimestampMeta":false, "extras":{"id":1}, "fastestLocationUpdateInterval":10000, "forceReloadOnBoot":false, "forceReloadOnGeofence":false, "forceReloadOnHeartbeat":false, "forceReloadOnLocationChange":false, "forceReloadOnMotionChange":false, "forceReloadOnSchedule":false, "foregroundService":true, "geofenceInitialTriggerEntry":true, "geofenceProximityRadius":1000, "geofenceTemplate":"", "headers":{}, "headlessJobService":"com.transistorsoft.backgroundgeolocation.HeadlessJobService", "heartbeatInterval":600, "httpRootProperty":"location", "httpTimeout":60000, "isMoving":false, "locationTemplate":"", "locationTimeout":60, "locationUpdateInterval":1000, "locationsOrderDirection":"ASC", "logLevel":5, "logMaxDays":3, "maxBatchSize":-1, "maxDaysToPersist":1, "maxRecordsToPersist":-1, "method":"POST", "minimumActivityRecognitionConfidence":75, "notificationColor":"", "notificationLargeIcon":"", "notificationPriority":0, "notificationSmallIcon":"", "notificationText":"Location Service activated", "notificationTitle":"", "params":{"device":{"uuid":"0feb9540a60aa9d7", "model":"SM-G960U", "version":"8.0.0"}}, "persist":true, "schedule":["2019-01-15-11:03 2019-01-15-12:03"], "startOnBoot":true, "stationaryRadius":25, "stopAfterElapsedMinutes":0, "stopOnStationary":false, "stopOnTerminate":false, "stopTimeout":1, "triggerActivities":"in_vehicle, on_bicycle, on_foot, running, walking", "url":"https://{our url}", "enabled":true, "schedulerEnabled":true, "trackingMode":1, "odometer":0, "isFirstBoot":false}
Not sure if it is caused by schedule.
Another thing I noticed that I think could be indication of bug. If I register listener on schedule BackgroundGeolocation.on('schedule', (state) => { console.log('[schedule] -', state); }); it will crash within following callback, toJson is undefined. If I remove listener, crash goes away Api.createScheduleCallback = function (callback) { return new TSScheduleCallback({ onSchedule: function (event) { callback(JSON.parse(event.toJson().toString())); } }); };
I'm using TNS 5.1
Thanks.