cowbell / cordova-plugin-geofence

Geofencing plugin for cordova
Apache License 2.0
264 stars 318 forks source link

onNotificationClicked not called iOS 10 + Android 7 Ionic 3 #256

Open flightknight22 opened 6 years ago

flightknight22 commented 6 years ago

Ionic: 3.19.0 iOS 10 Android 7

I am not able to trigger onNotificationClicked.

This is my code.

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, public geolocation: Geolocation) { platform.ready().then(() => {

  console.log('alright');
  this.geofencePlugin =  (<any>window).geofence;

  this.geofencePlugin.initialize().then((initStatus) => {
    console.log("Geofence Plugin has been initialized", initStatus);

    this.geofencePlugin.onNotificationClicked = function (notificationData) {
      console.log("App opened from Geo Notification!", notificationData);
    };
  }).catch((error) => {
    console.error(error);
  });

  statusBar.styleDefault();
  splashScreen.hide();
});

}

This is how my notification is formed:

let fenceTwo = {
  id: '69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb', //any unique ID
  latitude:       lat, //center of geofence radius
  longitude:      long,
  radius:         100, //radius to edge of geofence in meters
  transitionType: 3, //see 'Transition Types' below
  notification: { //notification settings
    id:             1, //any unique ID
    title:          'You At Home', //notification title
    text:           'You just arrived to Home city center.', //notification body
    openAppOnClick: true, //open app when notification is tapped
    data: {name:'test'}
  }
};

I am wondering if someone else has had issues with this too.

ghost commented 6 years ago

Hello, I'm facing the same issue and also the app restart process when taping on a notification (if app was not closed). Did you find a workaround ?

Thank you !

ghost commented 6 years ago

Sorry, I finally got it to work today. My problem was the missing "data" property in the fence Object. So for me it work fine in an Android Ionic 2 project. Thanks.