Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Aug 1, 2023 · 14 comments

Comments

@poorvasha-pss
Copy link

poorvasha-pss commented Aug 1, 2023

Your Environment

  • Plugin version: 4.11.1

  • Platform: iOS and Android

  • OS version: Androi(12) adn iOS(16.4)

  • Device manufacturer / model: Android (Redmi Note 10 (13.0.4)) and iOS (iPhone XR)

  • Flutter info (flutter doctor): image

  • Plugin config:

 // 1.  Listen to events (See docs for all 13 available events).
    bg.BackgroundGeolocation.onMotionChange(_onMotionChange);
    bg.BackgroundGeolocation.onActivityChange(_onActivityChange);
    bg.BackgroundGeolocation.onConnectivityChange(_onConnectivityChange);
    bg.BackgroundGeolocation.onGeofence(_onGeofence);

    bg.TransistorAuthorizationToken token =
        await bg.TransistorAuthorizationToken.findOrCreate(
            orgname, username, 'https://tracker.transistorsoft.com');

    // 2.  Configure the plugin
    bg.BackgroundGeolocation.ready(bg.Config(
            //schedule: ,
            reset:
                false, // <-- lets the Settings screen drive the config rather than re-applying each boot.
            // Convenience option to automatically configure the SDK to post to Transistor Demo server.
            transistorAuthorizationToken: token,
            // Logging & Debug
            debug: false,
            logLevel: bg.Config.LOG_LEVEL_VERBOSE,
            // Geolocation options
            desiredAccuracy: bg.Config.DESIRED_ACCURACY_NAVIGATION,
            distanceFilter: 10.0,
            // Activity recognition options
            stopTimeout: 5,
            backgroundPermissionRationale: bg.PermissionRationale(
                title:
                    "Allow {applicationName} to access this device's location even when the app is closed or not in use.",
                message:
                    "This app collects location data to enable recording your trips to work and calculate distance-travelled.",
                positiveAction: 'Change to "{backgroundPermissionOptionLabel}"',
                negativeAction: 'Cancel'),
            // HTTP & Persistence
            autoSync: true,
            // Application options
            stopOnTerminate: false,
            startOnBoot: true,
            enableHeadless: true,
            heartbeatInterval: 60))
        .then((bg.State state) async {
      print('[ready] ${state.toMap()}');
      print('[didDeviceReboot] ${state.didDeviceReboot}');
      _enabled = state.enabled;
      _isMoving = state.isMoving ??= false;
      bg.BackgroundGeolocation.start();
      bg.BackgroundGeolocation.changePace(_isMoving);
      bg.BackgroundGeolocation.startGeofences();
      if (state.schedule != null && state.schedule!.isNotEmpty) {
        bg.BackgroundGeolocation.startSchedule();
      }
      CommonFunction.giveSuccessToast("Start Geofence Tracking");
    }).catchError((error) {
      print('[ready] ERROR: $error');
    });

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
@poorvasha-pss poorvasha-pss changed the title events such as onGeofence, onLocation, and onMotionChange not getting triggered sometimes in Android and in killed state the events are never triggered events such as onGeofence, onLocation, and onMotionChange not getting triggered sometimes in Android, iOS and in killed state the events are never triggered Aug 1, 2023
@poorvasha-pss poorvasha-pss changed the title events such as onGeofence, onLocation, and onMotionChange not getting triggered sometimes in Android, iOS and in killed state the events are never triggered 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. Aug 1, 2023
@christocracy
Copy link
Member

See https://dontkillmyapp.com

@poorvasha-pss
Copy link
Author

poorvasha-pss commented Aug 3, 2023

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
Copy link
Member

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
Copy link
Author

Thank you, we will try and let you know

@poorvasha-pss
Copy link
Author

poorvasha-pss commented Aug 11, 2023

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
Copy link
Member

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

@poorvasha-pss
Copy link
Author

poorvasha-pss commented Aug 11, 2023

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
Copy link
Member

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

any possible to the give geofence radius below 200 ?

NO.

@poorvasha-pss
Copy link
Author

poorvasha-pss commented Aug 11, 2023

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
Copy link
Member

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
Copy link
Member

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

  • Nexus 4 @ 4.4.4
  • Nexus 5 @ 6.0.1
  • Motorola Moto G @ 6.0.0
  • Google Pixel @ 10
  • Google Pixel 3a @ 12
  • Google Pixel 6 @ 13
  • Samsung Galaxy S20 FE @ 13
  • Samsung J @ 6.0.1
  • Samsung A510 @ 8.0.0
  • Huawei P20 Lite (ANE-LX3) @ 8.0.0
  • XIAOMI MI A2 Lite @ 10.0.0
  • Nokia TA-1027 @ 8.0.0
  • OnePlus A5010 @ 9.0.0

@christocracy
Copy link
Member

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
Copy link
Member

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

@poorvasha-pss
Copy link
Author

Thanks for the Details

@transistorsoft transistorsoft deleted a comment from poorvasha-pss Aug 16, 2023
@transistorsoft transistorsoft locked as off-topic and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants