transistorsoft / flutter_background_geolocation

Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
https://www.transistorsoft.com/shop/products/flutter-background-geolocation
Other
652 stars 241 forks source link

Initial Geofence events missed for IOS handlers when the app is launched as a service form the background #797

Closed stevegaunt closed 5 months ago

stevegaunt commented 2 years ago

Your Environment

bg.Config( // tracking turning off issue is present on both android and ios: we don't want to set preventSuspend to true because it will increase our battery drain dramatically // preventSuspend: true, // heartbeatInterval: 60, autoSync: true, autoSyncThreshold: 20, desiredAccuracy: Config.DESIRED_ACCURACY_HIGH, distanceFilter: 50.0, elasticityMultiplier: 4.0, geofenceModeHighAccuracy: true, stopOnTerminate: false, startOnBoot: true, logLevel: Config.LOG_LEVEL_INFO, logMaxDays: 1, reset: kDebugMode, debug: kDebugMode, locationAuthorizationRequest: 'Always', enableHeadless: true, url: Config.LOCATION_API_URL, headers: headers, batchSync: true, maxBatchSize: 500, maxRecordsToPersist: 100000, maxDaysToPersist: 7, backgroundPermissionRationale: bg.PermissionRationale( title: "Allow {applicationName} to access this device's location even when closed or not in use?", message: "This enables the automatic logging", positiveAction: "Change to \"{backgroundPermissionOptionLabel}\"", negativeAction: "")); }

bg.onGeofence((GeofenceEvent event) { print('[onGeofence] ${event}'); });


## Expected Behavior
The geofence exit event correctly starts the IOS app as a service.
the call-back for the bg.onGeofence should get the initial geofence events that initiated starting the IOS app as a service

## Actual Behavior

The initial geofence event doesn't get handled, only additional geoevents  from once the app as been started as a service gets handled.

## Steps to Reproduce
<!--- reproduce this issue; include code to reproduce, if relevant -->

1.  move to a geofence location 
2. terminate  the app 
3. leave the geofence
4. the geofence event doesn't get handled.

## Context
We need to be able to know when geofences get entered/exit even if the app has been terminated.

## Debug logs
<!-- include iOS / Android logs
- ios XCode logs,
- use #getLog #emailLog methods (@see docs)
- Android: $ adb logcat -s TSLocationManager
-->
<details>
    <summary>Logs</summary>

``` <!-- syntax-highligting:  DO NOT REMOVE -->
PASTE_YOUR_LOGS_HERE

christocracy commented 2 years ago

Register event-listeners before calling .ready(), not after.

stevegaunt commented 2 years ago

@christocracy there currently are.

bg.BackgroundGeolocation.onGeofence((bg.GeofenceEvent event) async {

   log('[geofence] ${event.identifier}, ${event.action}');
});
bg.BackgroundGeolocation.onGeofencesChange((bg.GeofencesChangeEvent event) async {

  log('[GeofencesChangeEvent off] ${event.off}');
 log('[GeofencesChangeEvent on] ${event.on}');
});
//this config is **only** used for the first install and is ignored thereafter. It becomes the default.
var locationTrackingConfig = await sdk.getBaseLocationConfig(deviceInfoHeadersFactory);

try {
  await  bg.BackgroundGeolocation.ready(locationTrackingConfig);
} catch (error, stack) {
  CrashReporting.instance.recordError(error, stack);
}
christocracy commented 2 years ago

I've been running the /example app for years on my main iOS device (currently iPhone 13 Pro @ 15.5). I constantly monitor about 15 geofences throughout my neighbourhood.

I just took a little bike ride.

I am not able to reproduce the issue "Initial Geofence events missed for IOS handlers when the app is launched as a service form the background".

Opening the app after riding out of a geofence:

IMG_1811

Posted events to demo server:

Screen Shot 2022-07-21 at 4 00 08 PM
iphonedev4radixweb commented 2 years ago

Hello @christocracy, I need to track geofence event action in the terminate state of the app. In IOS it's not working, I have also tried preventSuspend true in geofence config. Please help me with that. Thanks in advance!

Software Version: 15.3.1 Device: iPhone X

christocracy commented 2 years ago

I have also tried preventSuspend tru

This has nothing to do with geofence firing.

Software Version: 15.3.1

This os version is know to have bugs. Upgrade to latest.

iphonedev4radixweb commented 2 years ago

Okay, then I will not use preventSuspend & let me try in another version. I will get back to you. Thanks!

github-actions[bot] commented 6 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 5 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.