Background Only Geofences in 1.8
Opened this issue · 10 comments
Your Environment
- Plugin version: 1.8.0
- Platform: Android
- OS version: 8.1.0
- Device manufacturer / model: Google Pixel 2
- Nativescript version (
tns info
):
┌──────────────────┬─────────────────┬────────────────┬─────────────┐
│ Component │ Current version │ Latest version │ Information │
│ nativescript │ 3.4.2 │ 3.4.2 │ Up to date │
│ tns-core-modules │ 3.4.0 │ 3.4.0 │ Up to date │
│ tns-android │ 3.4.1 │ 3.4.1 │ Up to date │
│ tns-ios │ 3.4.1 │ 3.4.1 │ Up to date │
└──────────────────┴─────────────────┴────────────────┴─────────────┘
- Plugin config
let options = {
license: 'xxx',
/* *****
[Geolocation] Common Options
* *****/
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_LOW,
distanceFilter: 150,
/* *****
[Geolocation] iOS Options
* *****/
stationaryRadius: 100,
useSignificantChangesOnly: true,
/* *****
[Activity Recognition] iOS Options
* *****/
disableMotionActivityUpdates: true,
/* *****
HTTP & Persistence Options
* *****/
url: LsApiPathConfig.API_URL + LsApiPathConfig.USER_LOCATION,
extras: this.getBackgroundGeolocationExtras(),
httpRootProperty: '.',
maxRecordsToPersist: 1,
/* *****
[Application] Common Options
* *****/
stopOnTerminate: false,
startOnBoot: true,
heartbeatInterval: 300,
/* *****
[Application] Android Options
* *****/
foregroundService: false,
notificationTitle: 'LiveShopper',
notificationText: 'Location service activated',
notificationIcon: 'drawable/ls_notification',
/* *****
Logging and Debug Options
* *****/
debug: false,
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
logMaxDays: 3
};
Expected Behavior
The plugin will start monitoring geofence events on close.
Actual Behavior
When I call BackgroundGeolocation.startGeofences
in the android activitiyStoppedEvent
the app crashes
Steps to Reproduce
- Subscribe to the activity stopped event
app.android.on(app.AndroidApplication.activityStoppedEvent, (args: any) => {
startGeofences();
});
- Start Geofence monitoring in the event
Context
I am attempting to only monitor geofences while the app is closed or in the background. I start the geofences when the app enters background. And also in the activity created event so that it starts when android restarts the app in the background. This worked fine before I updated the plugin to 1.8 and nativescript to ^3.4.
Debug logs
02-14 11:07:52.581 6728 6728 E AndroidRuntime: at com.tns.Runtime.callJSMethodNative(Native Method)
System.err: com.tns.NativeScriptException:
System.err: Calling js method onSuccess failed
System.err:
System.err: TypeError: Cannot read property 'getIntent' of undefined
System.err: File: "file:///data/data/com.liveshopper.mobile/files/app/tns_modules/nativescript-background-geolocation-lt/background-geolocation.js, line: 624, column: 47
System.err:
System.err: StackTrace:
System.err: Frame: function:'BackgroundGeolocation.init', file:'file:///data/data/com.liveshopper.mobile/files/app/tns_modules/nativescript-background-geolocation-lt/background-geolocation.js', line: 624, column: 48
System.err: Frame: function:'BackgroundGeolocation.getAdapter', file:'file:///data/data/com.liveshopper.mobile/files/app/tns_modules/nativescript-background-geolocation-lt/background-geolocation.js', line: 639, column: 18
System.err: Frame: function:'BackgroundGeolocation.startGeofences', file:'file:///data/data/com.liveshopper.mobile/files/app/tns_modules/nativescript-background-geolocation-lt/background-geolocation.js', line: 210, column: 18
System.err: Frame: function:'', file:'file:///data/data/com.liveshopper.mobile/files/app/shared/utils/app-event-setup.util.js', line: 45, column: 76
System.err: Frame: function:'onSuccess', file:'file:///data/data/com.liveshopper.mobile/files/app/tns_modules/nativescript-background-geolocation-lt/background-geolocation.js', line: 112, column: 17
System.err:
System.err: at com.tns.Runtime.callJSMethodNative(Native Method)
System.err: at com.tns.Runtime.access$2400(Runtime.java:34)
System.err: at com.tns.Runtime$3.run(Runtime.java:1099)
System.err: at android.os.Handler.handleCallback(Handler.java:789)
System.err: at android.os.Handler.dispatchMessage(Handler.java:98)
System.err: at android.os.Looper.loop(Looper.java:164)
System.err: at android.app.ActivityThread.main(ActivityThread.java:6541)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
1.9.0-beta.3
released. Be sure to do this
@christocracy I finally got time to test out updating the app to 1.9.0-beta.4
. The good news is it no longer crashes! Unfortunately, I no longer get geofence events sent to my http endpoint in the background as I did before.
Is there anything special that changed with the newest version when setting up geofences to get it to send the http post like before?
I tested it out by starting at one geofence location, walking to another, waiting for a few minutes, and then walking back to the first.
Here's the emailLog
info.
{
"activityRecognitionInterval": 10000,
"allowIdenticalLocations": false,
"autoSync": true,
"autoSyncThreshold": 0,
"batchSync": false,
"debug": true,
"deferTime": 0,
"desiredAccuracy": 0,
"desiredOdometerAccuracy": 100,
"disableElasticity": false,
"disableStopDetection": false,
"distanceFilter": 10,
"elasticityMultiplier": 1,
"enableHeadless": true,
"enableTimestampMeta": false,
"extras": {
"date": 1541439204,
"isInBackground": false,
"isIos": false,
"userToken": "wAcF2QjJJtV2PkyrP5SxxdhE2YA3",
"pushToken": "dlsJMhKMJYw:APA91bFcbbS3PqZqb-u8kQ5lICTI9rko7s9K5PIl--ikrPoRgheW1_GIlXyqMjZ0GrM6v8cslo5fDiezILEbSIXfYJs_2f_zsz2i7QgH0YAV7Dt2H3kLFmwfHa4GJjFNFnnLcFYGht6o"
},
"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": 300,
"httpRootProperty": ".",
"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": -2,
"notificationSmallIcon": "",
"notificationText": "Locating nearby tasks! (Long press to hide notification.)",
"notificationTitle": "LiveShopper",
"params": {},
"persist": true,
"schedule": [],
"startOnBoot": true,
"stationaryRadius": 25,
"stopAfterElapsedMinutes": 0,
"stopOnStationary": false,
"stopOnTerminate": false,
"stopTimeout": 5,
"triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking",
"url": "https:\/\/fuzzy-dragonfly-73.localtunnel.me\/user-location",
"enabled": false,
"schedulerEnabled": false,
"trackingMode": 0,
"odometer": 81.15462493896484,
"isFirstBoot": false
}
And here's the log file:
background-geolocation.log
There are no geofences firing in your logs. You will not get a geofence event sent to your end-point if no geofence events occur.
I did not change anything in my configuration, or implementation other than updating the plugin.
Is there anything special that changed with the newest version when setting up geofences to get it to send the http post like before?
I tested it out by starting at one geofence location, walking to another, waiting for a few minutes, and then walking back to the first.
It has nothing to do with HTTP. The geofences are not firing.
You can see in the logs that the geofences are being created and monitored. They are not firing.
- Are you using a min radius of 200 meters?
- Is WiFi enabled on device?
- Location Mode art to “High Accuracy”?
I understand it has nothing to do with HTTP. I should have rephrased that when I asked it again.
Is there anything special that changed with the newest version when setting up geofences to get it to FIRE GEOFENCES like before?
To answer your questions:
- Are you using a min radius of 200 meters?
- I assume you are talking about the radius on the geofence here. These are set to 100 per your documentation.
- Is WiFi enabled on device?
- Yes.
- Location Mode art to “High Accuracy”?
- It is never changed from the default value. Which I believe is
0
or "HIGHEST POWER, HIGHEST ACCURACY"
- It is never changed from the default value. Which I believe is
Here's one of the geofences:
{
"identifier": "-KxsBI2uRgLXppk8ogGT",
"radius": "100",
"latitude": 41.059098,
"longitude": -83.589661,
"notifyOnEntry": true,
"notifyOnExit": true,
"notifyOnDwell": true,
"loiteringDelay": 30000,
"extras": {
"location": "-KxsBI2uRgLXppk8ogGT",
"campaign": "-KwuecyexbJW5Z5fvuuP",
"user": "wAcF2QjJJtV2PkyrP5SxxdhE2YA3"
}
}
Is there anything special that changed with the newest version when setting up geofences to get it to FIRE GEOFENCES like before?
No.
These are set to 100
The docs are mistaken. It should read minimum is 200
. Change your radius to 200
.
t is never changed from the default value. W
I'm not talking about the plugin config. I'm talking about your Android Device Settings -> Location.
I updated it to 200. And the device is configured to use wifi for high accuracy GPS. Still no events.
My issue here is that it works when I run v1.8 but not 1.90-beta.4. If I downgrade to 1.8 and go for the exact same walk, I get geofence events firing without changing any configuration on my device or the plugin.
@christocracy I am coming back to this issue again after some time away working on other projects. I am still experiencing the issue above when running background geofences only. I do not see any geofence events firing for Android. I am still using the configuration above, but I am now using version 1.9.1 of the background-geolocation-lt plugin.
With the configuration provided above I receive ENTER
events on iOS almost instantly after creating the geofence. This is as I expected it to behave. I have tested with a walk, and a drive across town. I do not get any geofence events.
Here is a recent email log from my last test:
{
"activityRecognitionInterval": 10000,
"allowIdenticalLocations": false,
"autoSync": true,
"autoSyncThreshold": 0,
"batchSync": false,
"debug": true,
"deferTime": 0,
"desiredAccuracy": 100,
"desiredOdometerAccuracy": 100,
"disableElasticity": false,
"disableStopDetection": false,
"distanceFilter": 150,
"elasticityMultiplier": 1,
"enableHeadless": false,
"enableTimestampMeta": false,
"extras": {
"date": 1557342331,
"isInBackground": true,
"isIos": false,
"userToken": "mZQ01aaw3rbMV9YJ4wNfrd41yJo1",
"pushToken": "cnb6kT7lpKM:APA91bEP-ZbwC7rsYkJ2chu9ux9WC45TUxYxrtcCsicC1PgdsDaZ97H5YNCpMoJq9AwanPiLo5oCbtGrFcQjw6Ny7LNacuHx75yqwBKEPH9QGFPj_M-xkkDq-R90tWKB3fA5r4y4Nlvs"
},
"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": 300,
"httpRootProperty": ".",
"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": -2,
"notificationSmallIcon": "",
"notificationText": "Locating nearby tasks! (Long press to hide notification.)",
"notificationTitle": "LiveShopper",
"params": {},
"persist": true,
"schedule": [],
"startOnBoot": true,
"stationaryRadius": 100,
"stopAfterElapsedMinutes": 0,
"stopOnStationary": false,
"stopOnTerminate": false,
"stopTimeout": 5,
"triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking",
"url": "https:\/\/api.liveshopper.com\/v1-dev\/user-location",
"enabled": true,
"schedulerEnabled": false,
"trackingMode": 0,
"odometer": 36.359375,
"isFirstBoot": false
}
@christocracy Can you provide any insight as to why the geofence events aren't firing?