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

heartbeatInterval is not honored in background mode on Android and IOS and Need help in understanding .on("location") API. #354

Closed
vedantterkar opened this issue May 25, 2017 · 11 comments

Comments

@vedantterkar
Copy link

vedantterkar commented May 25, 2017

As Location update interval is 15mins on IOS; I tried to use .on("heartbeat")API with heartbeatInterval: 60 (60 secs).

It works fine in both IOS and Android in foreground and background mode; But There is one issue which I noticed recently; After some time Let us say 10mins; instead of firing heartbeat event after specified interval (60sec) It was firing it after much larger time (of 5minutes on Android and of 15mins on IOS).

Environment

Plugin version: 2.7.0

Platform: Android

OS version: 6

Cordova version (cordova -v): 6.5.0

Plugin config


this.config = {
      desiredAccuracy: 10,
      stationaryRadius: 0,
      distanceFilter: 0,
      debug: true,
      stopOnTerminate: false,
      startForeground: true,
      locationProvider: 1,
      locationUpdateInterval: 60 * 1000
      fastestInterval: (60 * 1000) / 2,
      activitiesInterval: (60 * 1000) / 2,
      stopOnStillActivity: false,
      pauseLocationUpdates: false,
      activityType: 'AutomotiveNavigation',
      notificationText: this.notificationText,
      notificationTitle: this.notificationTitle,
      useSignificantChangesOnly: false,
      locationAuthorizationRequest: 'Always',
      activityRecognitionInterval: 100,
      heartbeatInterval: 60,
      preventSuspend: true,
      trackingMode: 'location'
     
    };
  
        platform.ready().then(() => {
          alert("Bingo!");
          backgroundGeolocation = (<any>window).BackgroundGeolocation;
           backgroundGeolocation.on("location", this.setLocation, this.handleError );  
           backgroundGeolocation.configure(this.config, this.setLocation, this.handleError);
             this.backgroundGeolocation.on('heartbeat',function(params){
             console.log("heartbeat fired");
             console.log("time: ", (new Date()).toLocaleTimeString());
             },
             function(err){
              console.error(err);
             }); 
        });
setLocation(location: any) {
backgroundGeolocation.start();
console,log("location Triggered!");
   backgroundGeolocation.finish();
    
  }
handleError(error:any)
{
console.error(error);
}

Expected Behavior

heartbeat event should be fired at specified interval always it should not be delayed.

Actual Behavior

After some time Let us say 10mins; instead of firing heartbeat event after specified interval (60sec) It was firing it after much larger time of 5minutes.

Context

Implementing .on("heartbeat") listener.

Also I need little help in understanding .on("location") API.
As mentioned in documentation(https://github.com/transistorsoft/react-native-background-geolocation/blob/master/docs/README.md#location);
.on("location") will be fired as soon as new location is detected, That means on IOS it'll be fired too right? or will it be fired after 15mins(Interval for location update on IOS) only even if .on('location') is changed?

And what is the minimum distance needs to be travelled to trigger .on('location')?

Thanks in advance.

@vedantterkar vedantterkar changed the title heartbeatInterval is not honored in background mode Android and IOS and Need help in understanding .on("location") API. heartbeatInterval is not honored in background mode on Android and IOS and Need help in understanding .on("location") API. May 25, 2017
@christocracy
Copy link
Member

What device make/model are you using? Vendor os can add their own battery-saving overrides to throttle timers.

@vedantterkar
Copy link
Author

For Android: Samsung Galaxy S5.
For IOS: Iphone 7.

@christocracy
Copy link
Member

Samsung's Smart Manager can cause timers to throttle on Android.

@vedantterkar
Copy link
Author

@christocracy ,

Can you please help in IOS case? Now it is taking more than 30mins. No location is posted to server when screen is locked but as soon as I turn on screen multiple locations are posted.

@christocracy
Copy link
Member

I'm working on another issue reported about iOS heartbeat. I've confirmed that iOS 10 has made a change to throttle timers running in the background.

Are you even listening to the heartbeat event?

@vedantterkar
Copy link
Author

I've written Listener with logging statement; Logs are printed fine in Android but that is not the case in IOS.
Sometimes logs are also not generated in IOS.

Also location updation to server is taking a lot of time: started from 1min then 5mins then shifted to 15mins; Now it is taking more than 30mins in background mode (On IOS).

On Android it is still stuck to 5mins.

@christocracy
Copy link
Member

It's a very simple question: yes or no:

Are you even listening to the heartbeat event?

@vedantterkar
Copy link
Author

yes

@christocracy
Copy link
Member

You are confused with Mauron85's plugin. The following config options are invalid:

locationProvider: 1,
      fastestInterval: (60 * 1000) / 2,
      activitiesInterval: (60 * 1000) / 2,
      stopOnStillActivity: false,
      pauseLocationUpdates: false,
      trackingMode: 'location'

Also, read the docs for the #configure method. The API of this plugin is completely different than Mauron85's.

This plugin's #configure successFn does not receive a location -- it receives the current plugin state.

bgGeo.configure(config, function(state) {
  console.log('Plugin is configured and ready to use.  Current state: ', state);
  bgGeo.start();  // <--- start tracking  
});

You need to forget what you learned about Mauron85 and start from scratch

@vedantterkar
Copy link
Author

vedantterkar commented May 25, 2017

I've uninstalled that plugin.

Now it is not there in my $cordova plugins. I changed the configuration object too.

Now configuration object is like:

this.config = {
      desiredAccuracy: 10,
      stationaryRadius: 0,
      distanceFilter: 0,
      debug: true,
      stopOnTerminate: false,
      activityType: 'AutomotiveNavigation',
      notificationText: this.notificationText,
      notificationTitle: this.notificationTitle,
      useSignificantChangesOnly: false,
      locationAuthorizationRequest: 'Always',
      activityRecognitionInterval: 100,
      heartbeatInterval: 60,
      preventSuspend: true,
      trackingMode: 'location'
     
    };

But Still the issue persists. I don't want to call .start() in successCallBackFN so I'm doing it on some other event and It is working fine.

Issue with heartbeat is still occurring. Now it is happening in android too (Delayed by 30mins).

Thanks.

@christocracy
Copy link
Member

The plugin has not such config trackingMode. This is a read-only state property. Remove it.

Did you read what I said above about iOS heartbeat?

I'm working on another issue reported about iOS heartbeat. I've confirmed that iOS 10 has made a change to throttle timers running in the background.

You cannot count on a regular heartbeat occurring.

I suggest you try adding a background-fetch listener. The iOS-only background-fetch plugin is already installed and waiting for you at window.BackgroundFetch. You do not need to install it. BackgroundGeolocation includes it as a dependency and uses it internally. You're free to implement the Javascript API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants