Geofence plugin notifications not working on iOS

Hello, Preformatted text I am using geofence notifications, I modified my code and my updated code is given below

  private addGeofence(lat,lon){
    //options describing geofence
    let fence = {
      id: '69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb', //any unique ID
      latitude: Number(this.latitude), //center of geofence radius
      longitude: Number(this.longitude),
      radius: 10000, //radius to edge of geofence in meters
      transitionType: 3, //see 'Transition Types' below
      notification: { //notification settings
        id: 1, //any unique ID
        title: 'Oober', //notification title
        text: "You are in customer's location. Tap to start your task.", //notification body
        openAppOnClick: true //open app when notification is tapped
      }
    }
    this.geofence.onTransitionReceived().subscribe(() => {
          this.presentAlert('onTransitionReceived');
        });
    this.geofence.addOrUpdate(fence).then(
      () => {
        console.log('Geofence added');
        this.presentAlert('Geofence added');
      },
      (err) => {
        console.log('Geofence failed to add');
        this.presentAlert(err);
      }
    );
  }

This code is working fine and giving me alert ‘Geofence added’. but after entering the fence, I am not getting notification.

Any clues, please??

My ionic info is given below

Cordova CLI: 6.4.0 
Ionic Framework Version: 2.3.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.4
ios-deploy version: 1.9.1 
ios-sim version: 5.0.13 
OS: macOS Sierra
Node Version: v7.4.0
Xcode version: Xcode 8.3.3 Build version 8E3004b

my dependencies on package.json are

 "dependencies": {
    "@angular/common": "2.4.8",
    "@angular/compiler": "2.4.8",
    "@angular/compiler-cli": "2.4.8",
    "@angular/core": "2.4.8",
    "@angular/forms": "2.4.8",
    "@angular/http": "2.4.8",
    "@angular/platform-browser": "2.4.8",
    "@angular/platform-browser-dynamic": "2.4.8",
    "@angular/platform-server": "2.4.8",
    "@ionic-native/background-geolocation": "^3.8.0",
    "@ionic-native/camera": "^3.12.1",
    "@ionic-native/core": "^3.9.2",
    "@ionic-native/geofence": "^3.12.1",
    "@ionic-native/geolocation": "^3.12.1",
    "@ionic-native/in-app-browser": "^3.9.2",
    "@ionic-native/keyboard": "^3.10.3",
    "@ionic-native/local-notifications": "^3.12.1",
    "@ionic-native/native-geocoder": "^3.12.1",
    "@ionic-native/sms": "^3.8.0",
    "@ionic-native/splash-screen": "3.1.0",
    "@ionic-native/status-bar": "3.1.0",
    "@ionic/storage": "^2.0.0",
    "ionic-angular": "2.3.0",
    "ionicons": "3.0.0",
    "rxjs": "5.0.1",
    "sw-toolbox": "3.4.0",
    "zone.js": "0.7.2"
  }

and plugin link is this.https://github.com/cowbell/cordova-plugin-geofence

Looking at the documentation at https://ionicframework.com/docs/native/geofence/:
Did you call initialize in the constructor successfully?
Does getWatched return the one you setup?

I did the same ,

I am getting following log in xcode

017-06-20 21:31:06.065567 Worker[5366:2180957] GeofencePlugin - Plugin initialization
2017-06-20 21:31:06.108663 Worker[5366:2180957] GeofencePlugin - GeoNotificationManager init
2017-06-20 21:31:06.118755 Worker[5366:2180957] THREAD WARNING: ['GeofencePlugin'] took '60.026367' ms. Plugin should use a background thread.
2017-06-20 21:31:06.121638 Worker[5366:2180957] WARN: Deprecated: The color input has been removed from HTML elements. Please add the `ion-text` attribute in order to use the color input. For example: `<a ion-text color="secondary">Link</a>`
2017-06-20 21:31:06.121914 Worker[5366:2180957] ionViewDidLoad TrackOrder
2017-06-20 21:31:06.237099 Worker[5366:2180957] Geofence Plugin Ready
2017-06-20 21:31:06.244851 Worker[5366:2181069] GeofencePlugin - GeoNotificationManager addOrUpdate
2017-06-20 21:31:06.257608 Worker[5366:2181069] GeofencePlugin - AddOrUpdate geo: {
  "latitude" : 28.619455,
  "notification" : {
    "id" : 1,
    "title" : "Title",
    "openAppOnClick" : true,
    "text" : "You are in customer's location. Tap to start your task."
  },
  "radius" : 100,
  "transitionType" : 3,
  "id" : "69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb",
  "longitude" : 77.38229200000001
}
2017-06-20 21:31:06.300861 Worker[5366:2180957] GeofencePlugin - Starting monitoring for region CLCircularRegion (identifier:'69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb', center:<+28.61945500,+77.38229200>, radius:10000.00m) lat 28.619455 lng 77.382292 of radius 100.0

Please have a look at this.

That looks pretty good I think.

Is the fence data correct?

1 Like

Yes, Data is correct and I am getting the same that I did setup.

2017-06-20 22:11:06.632865 Worker[5384:2186830] GeofencePlugin - AddOrUpdate geo: {
  "latitude" : 28.619455,
  "notification" : {
    "id" : 1,
    "title" : "Title",
    "openAppOnClick" : true,
    "text" : "You are in customer's location. Tap to start your task."
  },
  "radius" : 10000,
  "transitionType" : 3,
  "id" : "69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb",
  "longitude" : 77.38229200000001
}
2017-06-20 22:11:06.679631 Worker[5384:2186775] Watching :  [{
  "latitude" : 28.619455,
  "transitionType" : 3,
  "notification" : {
    "id" : 1,
    "title" : "Title",
    "openAppOnClick" : true,
    "text" : "You are in customer's location. Tap to start your task."
  },
  "radius" : 10000,
  "id" : "69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb",
  "longitude" : 77.38229200000001
}]
1 Like

I am out of ideas.

I would create a new blank project ( ionic start blank blank) and only implement the absolute bare basics with geofence and see if I could get it working on Android and iOS. If not, put it on Github and post here again so we can debug.

1 Like

If I go by the instructions for GeoFence on the Ionic Native page, it works on Android but not on iOS. I get an alert index.html [object Object] and I have looked all over for anyone who had something like that. There are other forks for the plugin such as https://github.com/EddyVerbruggen/cordova-plugin-geofence and others but I’m not sure how to define them in package.json and config.xml, and which one to use. Is there any idea how to get it to work properly ?

Create a new topic, add all information (e.g. what implementation of the plugin gives you that alert) and we will if we can help.

Unfortunately the Ionic Cloud Package has been nothing but a frustrating waste of time for me and many others, and yesterday I found a different solution - I rented a Mac, moved my code over, and did the Cordova and .ipa build directly on the Mac. To my surprise plugins that never worked before on iOS when building with the Ionic Cloud Package (like Screen Orientation, Local Notifications and GeoFence) are now finally working, and I noticed the screen response times on the iPhone much faster with the Mac build than with the Ionic Cloud Package build. And since the Android packaging doesn’t always succeed without any clear explanation, I’m going to start building directly with the Android SDK, and hopefully will be able to work with something reliable and stable.

@umasankar421 - pls let me know if issue is resolved, I am having same problem. Thanks

Sorry, I can’t get on to the Ionic Forum - I put in my email and password but it says the password is wrong.

I send for a pasword reset, but it says it doesn’t recognize my email addresss.

So I register from scratch and it says my email address is already being used…

Anyway, perhaps take a look at what I figured out here (down near the bottom) - I hope it helps you

@dovk, I am able to compile all code without error, though fence is registering perfectly but not receiving transition (enter/leave).

Perhaps send me some code or put it up in Github somewhere. If that doesn’t help we can set up that either I hook up to your machine via Teamviewer or you hook up to mine so we can get a better look and figure it out together.

Hi dovk. here is test fresh test app - https://github.com/brijesh-p/fenceiosIssue

you can change coordinates -src/app/app.component.ts

Thanks for your kind support

For starters, try defining the fence parameters as close as possible to what I did here https://github.com/dovk/geofence-fix in l_fence.ts

For example at some point I felt the id of the notification itself was causing problems, so try taking it off,

and do the rest as I did

I’ll go over the rest now

[https://avatars3.githubusercontent.com/u/26749318?s=400&v=4]https://github.com/dovk/geofence-fix

dovk/geofence-fixhttps://github.com/dovk/geofence-fix


Contribute to geofence-fix development by creating an account on GitHub.

Also do as I did and seperate to two array objects so that you have one for transitionType = 1 and one for transitionType = 2 instead of one with transitionType = 3

I have tried the solution but this is not working and can able to see may developers reported the Geofence iOS issue and still no final solution for that?

Hi,
Did you find any solution for this issue ?
I’m facing the same issue in my project.

Thanks