I am using geofence plugin in ionic2. Geofence plugin is working fine in Android and but in iOS, geofence is adding successfully but after entering or existing the geofence, notification is not coming.
and I am sending some local notification onTransitionReceived() is not working in iOS.
Here is my code
private addGeofence(lat,lon){
//options describing geofence
let fence = {
id: '69ca1b88-6fbe-4e80-a4d4-ff4d3748acdb', //any unique ID
latitude: this.latitude, //center of geofence radius
longitude: this.longitude,
radius: 100, //radius to edge of geofence in meters
transitionType: 1, //see 'Transition Types' below
// notification: { //notification settings
// id: 1, //any unique ID
// title: 'Title', //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.addOrUpdate(fence).then(
() => {
console.log('Geofence added');
//this.presentAlert('Geofence added');
this.geofence.onTransitionReceived().subscribe(() => {
//this.presentAlert('onTransitionReceived');
this.scheduleNotification();
});
},
(err) => {
console.log('Geofence failed to add');
this.presentAlert(err);
}
);
}
scheduleNotification() {
this.localnotification.schedule({
id: 100,
title: 'Tap to Start Task',
text: "You are in to customer's location. Tap to start your task.",
at: new Date(new Date().getTime() + 0.5 * 1000),
//at:this.geofence.onTransitionReceived(),
data: { mydata: "You are nearer to customer's location. Tap to start your task." }
});
}
Local notifications are working fine. But, In my case geofence is adding fine , I got to know that geofence is working with this addOrUpdate method. this method is adding the geofence for me but on entering or existing the geofence notifications are not coming.
So you are sure geofence is working? Did you test by adding some logging?
Because then you don’t have a geofence problem, but a notification problem and this topic title and information is all wrong.
FYI, geofence will fire its own notification while we enter into the fence or exit from the fence. I am talking about those notifications and are not working and those notifications are the part of geofence plugin.
Are you talking about [quote=“umasankar421, post:1, topic:95073”]
// notification: { //notification settings
// id: 1, //any unique ID
// title: ‘Title’, //notification title
// text: “You are in customer’s location. Tap to start your task.”, //notification body
// openAppOnClick: true //open app when notification is tapped
// }
[/quote]
?
Is this why you added additional localnotification to “fix” this?