Ionic Capacitor Geofence Problem

Hi everybody !

I want to use Geofence on my Ionic 3 Capacitor project, to locate the device’s position and notify the user when it is within range.

I found this plugin. I was able to build the project successfully, but when I run it, I have the following error in the console:

Object(...) is not a function
    at Geofence.initialize

The problem is in the file /node_modules/@ionic-native/geofence/ngx/index.js, because it does the following:

import { IonicNativePlugin, cordova, cordovaFunctionOverride } from '@ionic-native/core';

But neither cordova nor cordovaFunctionOverride. It exists Cordova an CordovaFunctionOverride but it is used in a different way.

Any ideas on how could solve this problem ? Or any alternatives ?

Thank you so much for your time!

Welcome to the Ionic Forums.

All @ionic-native/* packages must share the same major version at all times. I will bet that if you look in your package.json, you will see @ionic-native/geofence has major version 5 and @ionic-native/core is still on 4.x.

Thank you so much! It was that. I had to install ionic-native/geofence@4.20.0.

Now, mi project compiles and run perfect. But when I want to addOrUpdate I have this error message:

{
code: "UNKNOWN"
message: "Adding geofences failed - SystemCode: 1004"
}

Do you know what is happening ?

My code is:

    this.geofence.initialize().then(
      () => {
        let fence = {
          id: '69ca1b88-6fbe-asdfa-a4d4-vvv', //any unique ID
          latitude: -34.8992466, //center of geofence radius
          longitude: -57.95035889999999,
          radius: 10, //radius to edge of geofence in meters
          transitionType: 3, //see 'Transition Types' below
          notification: { //notification settings
            id: 6, //any unique ID
            title: 'You crossed a fence', //notification title
            text: 'You just arrived to Gliwice city center.', //notification body
            openAppOnClick: true //open app when notification is tapped
          }
        };

        this.geofence.addOrUpdate(fence).then(
          () => {
            console.log('Geofence added');
          },
          (err) => {
            console.log('Geofence failed to add', err);
          }
        );

      },
      (err) => console.log(err)
    );

this.geofence.initialize works well but not addOrUpdate

Thanks again.

In case it happens to any of you, the problem was that I had to enable the “Allow all the time” location in my app. But I had to do it in the device configuration, it does not give me the option in the application :frowning: