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

One callback in background geolocation #331

Closed
pascalrijk opened this issue Jul 19, 2016 · 7 comments
Closed

One callback in background geolocation #331

pascalrijk opened this issue Jul 19, 2016 · 7 comments
Labels

Comments

@pascalrijk
Copy link

Hi,

I am using the backgroundgeolocation on a ts page but the succes callback is only fired once. Can somebody tell me what the reason is for this problem?

ionic native: 3.3.7

ionic info output:
Cordova CLI: 6.2.0
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.0.0-beta.32
Ionic App Lib Version: 2.0.0-beta.18
OS: Distributor ID: Ubuntu Description: Ubuntu 14.04.3 LTS
Node Version: v5.6.0

@pascalrijk
Copy link
Author

this.platform.ready().then(() => {
BackgroundGeolocation.deleteAllLocations();
BackgroundGeolocation.configure(config)
  .then((location) => {
    // Fired only once
    this.addNewLocation(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 HTTP request is successful or not.
    // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
    // BackgroundGeolocation.finish(); // FOR IOS ONLY
  })
  .catch((error) => {
    console.log('BackgroundGeolocation error');
  });

// Turn ON the background-geolocation system.  The user will be tracked whenever they suspend the app.
BackgroundGeolocation.start().then(log => {
  console.log(log);
});
});

@ihadeed
Copy link
Collaborator

ihadeed commented Jul 20, 2016

Might be because they return promises, they should return Observables instead.

@pascalrijk
Copy link
Author

Thanks for your reply! That was the same thing I thought :) , When do you think this problem is solved?

@mlynch
Copy link
Collaborator

mlynch commented Aug 1, 2016

Changing this to be a sync since it's a non-standard behavior

@mlynch mlynch closed this as completed in 4e20681 Aug 1, 2016
@mlynch
Copy link
Collaborator

mlynch commented Aug 1, 2016

@pascalrijk can you try the code in master now? Just pushed a fix that changes the semantics to be this:

BackgroundGeolocation.configure((pos) => {
}, (err) => {
}, { // options ))

Also updated the config to match the most recent version of the plugin

@jvaclavik
Copy link

jvaclavik commented Aug 9, 2016

@mlynch: It works, thank you!

Steps to update from master:

  1. Download master
  2. Copy master to node_modules/ionic-native
  3. cd node_modules/ionic-native
  4. npm install
  5. npm run build
  6. Configure BackgroundGeolocation:
BackgroundGeolocation.configure((location) => {
  console.log('Geolocation: ' + location.latitude + ',' + location.longitude + ', ' + location.speed);
  BackgroundGeolocation.finish();
}, (error) => {
  console.log('BackgroundGeolocation error', error);
}, config);

7 . ionic serve and run

@mlynch
Copy link
Collaborator

mlynch commented Aug 9, 2016

An easier way to install from master:

npm install git+https://github.com/driftyco/ionic-native.git

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

No branches or pull requests

4 participants