transistorsoft / flutter_background_geolocation

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

events such as onGeofence, onLocation, and onMotionChange not getting triggered sometimes in alive state and never triggers in killed state in both Android and iOS. #1088

Open poorvasha-pss opened 1 year ago

poorvasha-pss commented 1 year ago

Your Environment

Expected Behavior

The _onGeofence event should trigger whenever user enter or exit the geofence radius in both app alive and killed state

Actual Behavior

  1. If user enter or exit the geofence radius, sometimes the _onGeofence event is triggering but sometimes it is not, the way we have tested is through walking
  2. The events are never triggered when the app is killed,

we have added the backgroundGeolocationHeadlessTask and registered that in main.dart and also configured _configureBackgroundFetch()

void _configureBackgroundFetch() async {
    BackgroundFetch.configure(
        BackgroundFetchConfig(
            minimumFetchInterval: 15,
            startOnBoot: true,
            stopOnTerminate: false,
            enableHeadless: true,
            requiresStorageNotLow: false,
            requiresBatteryNotLow: false,
            requiresCharging: false,
            requiresDeviceIdle: false,
            requiredNetworkType: NetworkType.NONE), (String taskId) async {
      print("[BackgroundFetch] received event $taskId");
      if (taskId == 'flutter_background_fetch') {
        try {
          // Fetch current position
          var location = await bg.BackgroundGeolocation.getCurrentPosition(
              samples: 1,
              extras: {"event": "background-fetch", "headless": false});
          print("[location] $location");
        } catch (error) {
          print("[location] ERROR: $error");
        }
      }

      // Test scheduling a custom-task in fetch event.
      BackgroundFetch.scheduleTask(TaskConfig(
          taskId: "com.transistorsoft.customtask",
          delay: 5000,
          periodic: false,
          forceAlarmManager: true,
          stopOnTerminate: false,
          enableHeadless: true));
      BackgroundFetch.finish(taskId);
    });
    CommonFunction.giveSuccessToast("Background fetch configured");
  }

Steps to Reproduce

  1. Add desired geofences
  2. Start Walking
  3. walk by entering and exiting from the given geofence radius
  4. The event should trigger both in live and killed state of the app

Context

We are trying to auto logging in user based on the given geofence radius, if user enter the given geofence radius we will be sending local notification that "you have entered the location" and we will do an api call to add timelog in Database, if user exit, as same as enter.

Debug logs

Logs ``` PASTE_YOUR_LOGS_HERE ```
christocracy commented 1 year ago

See https://dontkillmyapp.com

poorvasha-pss commented 1 year ago

Thank you Christocracy, we will take a look into it, it seems that there is no solution provided for iOS in dontkillmyapp.com site. is there any other thing we need to do for iOS to work in the terminated state?

christocracy commented 1 year ago

to do for iOS to work in the terminated state?

stopOnTerminate: false. Don’t disable wifi on device. Always ensure .ready(config) is executed each time app is launched.

poorvasha-pss commented 1 year ago

Thank you, we will try and let you know

poorvasha-pss commented 1 year ago

Hi Christocracy, some of the devices were not listed in the https://dontkillmyapp.com/ such as TECNO-AC8, and also on some other device even if we followed the instruction given in the https://dontkillmyapp.com/ still the geofence event is not getting triggered sometimes. Is there anything that you are triggering the events based on the speed per second?

christocracy commented 1 year ago

There is nothing that can be done to forcibly evaluate / fire geofences. Geofences are managed purely by the OS.

poorvasha-pss commented 1 year ago

Okay, Thank you Christ, some of the devices were not listed in the https://dontkillmyapp.com/ such as TECNO-AC8, is there anything that we can do to fix it? and also is there any possible to the give geofence radius below 200 ?

christocracy commented 1 year ago

They are probably not listed because they’re not popular.

any possible to the give geofence radius below 200 ?

NO.

poorvasha-pss commented 1 year ago

Sometimes even if we followed the instruction given in the https://dontkillmyapp.com/ still the geofence event is not getting triggered in terminated state. Can you please help us to identify the issue of the inconsistent event triggering or there is issue with the background process?

christocracy commented 1 year ago

Some devices just don’t work properly. It’s the fault of the manufacturer.

there is nothing I can do. I implement the Geofencing api according to public Android API docs. Geofences are managed purely by the OS.

christocracy commented 1 year ago

I regularly field test on the following devices. Geofences don’t fail.

christocracy commented 1 year ago

I suggest you test my demo app from play store. It’s linked in the readme.

you can add geofences by long-pressing on the map (in the Advanced App).

christocracy commented 1 year ago

Also, don’t test geofences in emulator / mock location app. Test outdoors with real movement.

poorvasha-pss commented 1 year ago

Thanks for the Details