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

ionic 4 when app minimize it not work #30

Open
Jawwad-Parekh opened this issue Jan 9, 2020 · 1 comment
Open

ionic 4 when app minimize it not work #30

Jawwad-Parekh opened this issue Jan 9, 2020 · 1 comment

Comments

@Jawwad-Parekh
Copy link

i try it but it giving issue i started it on click but it not working in background? Like this

startBackgroundGeolocation() {
const config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 1,
distanceFilter: 1,
interval:15000,
debug: true, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false // enable this to clear background location settings when the app terminates

};

this.backgroundGeolocation.configure(config).then(() => {
  this.backgroundGeolocation
    .on(BackgroundGeolocationEvents.location)
    .subscribe((location: BackgroundGeolocationResponse) => {
      // alert(location.longitude);
      this.sendGPS(location);

      // IMPORTANT:  You must execute the finish method here to inform the native plugin that you're finished,
      // and the background-task may be completed.  You must do this regardless if your operations are successful or not.
      // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
    });
});

// start recording location
this.backgroundGeolocation.start();

// If you wish to turn OFF background-tracking, call the #stop method.
// this.backgroundGeolocation.stop();

}

sendGPS(location) {
if (location.speed == undefined) {
location.speed = 0;
}
let timestamp = new Date(location.time);

this.http
  .post(
    this.gps_update_link, // backend api to post
    {
      lat: location.latitude,
      lng: location.longitude,
      speed: location.speed,
      timestamp: timestamp
    },
    {}
  )
  .then(data => {
    this.Data.push({lat : location.latitude , lon : location.longitude , spe : location.speed , time : location.timestamp});
    console.log(data.status);
    console.log(data.data); // data received by server
    console.log(data.headers);
    this.backgroundGeolocation.finish(); // FOR IOS ONLY
  })
  .catch(error => {
    alert(error.status);
    alert(error.error); // error message as string
    alert(error.headers);
    this.backgroundGeolocation.finish(); // FOR IOS ONLY
  });

}

This is a code i am using please inform me what i am doing wrong?

@mobiliseapplabllp
Copy link

Hello
after android 8 android os will your background tracking for security reason. background geolocation tracking working fine on android 8 but after android 9 this is not working

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