Can i upgrade Background Geolocation plugin to version 3?

Hi!

I’ve followed the install instructions here: https://ionicframework.com/docs/native/background-geolocation/ and things seem to work fine. But when i go to the plugin repo (https://github.com/mauron85/cordova-plugin-background-geolocation) i see that the documentation is for version 3 of the plugin. The instructions at Ionic native pages installs version 2.x of the plugin. I tried to install the plugin version 3.x. But then My console complains about “plugin is not installed”, and the plugin won’t do what it’s supposed to.

Is there any way i can make version 3.x work with ionic native?

Hi !

I’m facing the same issue …
Did you find any solutions ?

Sorry, no solution for this yet.

Hi !
I find the solution in another post.
You have to use directly the cordova plugin, without ionic-native.

You just have to declare declare let BackgroundGeolocation: any; in the import section; and use it in your page :slight_smile:

Exemple :

import { Component } from '@angular/core';
import { IonicPage, ....... } from 'ionic-angular';
...
// Import the cordova plugin like this
declare let BackgroundGeolocation: any;

@IonicPage()
@Component({
  selector: 'page-navigation',
  templateUrl: 'navigation.html',
})
export class NavigationPage {

  // Don't import BackgroundGeolocation in the constructor
  constructor(public navCtrl: NavController, public navParams: NavParams) {

  ionViewDidLoad() {
    ...
    BackgroundGeolocation.configure(this.config);
    BackgroundGeolocation.on('location', (location) => {
      // handle your locations here
      // to perform long running operation on iOS
      // you need to create background task
      BackgroundGeolocation.startTask((taskKey) => {
        // execute long running task
        // eg. ajax post location
        // IMPORTANT: task has to be ended by endTask
        this.yourMethod(location);
        BackgroundGeolocation.endTask(taskKey);
      });
    });
    BackgroundGeolocation.on('error', function(error) {
      // Catch Error
    });
    // Turn ON the background-geolocation system.
    BackgroundGeolocation.start();
  }