Eduardo Albuquerque
Eduardo Albuquerque

Reputation: 543

Background Geolocation isn't a Observable

I need Implement a Background Geolocation in my app. I acess this ionic documentation, there shows the code below:

this.backgroundGeolocation.configure(config)
  .subscribe((location: BackgroundGeolocationResponse) => {

    console.log(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.
    this.backgroundGeolocation.finish(); // FOR IOS ONLY

  });

When I used this code in my app, my ts-lint accuse the configure(config) method is a Promise<any> and not a Observable, so, I cant use subscribe. I switched subscribe for then. But when I run, shows this error below:

ERROR Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
    at BackgroundGeolocation.configure (vendor.js:82333)
// error below ommited

Someone can help me?

Upvotes: 0

Views: 1470

Answers (1)

Eduardo Albuquerque
Eduardo Albuquerque

Reputation: 543

The problem is the Plugin version. In Ionic 3 this versions work fine:

config.xml file: <plugin name="cordova-plugin-mauron85-background-geolocation" spec="^2.2.5" />

package.json file: "@ionic-native/background-geolocation": "^3.14.0",

I found this answer in this repository.

In the Ionic v3 documentation is wrong, because there says we need use this commands:

$ ionic cordova plugin add cordova-plugin-mauron85-background-geolocation@alpha
$ npm install --save @ionic-native/background-geolocation@4

But we need use this commands to work fine and finally use the subscribe:

$ ionic cordova plugin add [email protected]
$ npm install --save @ionic-native/background-geolocation@3

Upvotes: 1

Related Questions