Every time I open the app, my app receives notifications each time, if i am on the location. How do I trigger the event only once in the location?
my code:
import { Geofence } from '@ionic-native/geofence';
@Injectable()
export class GeofenceProvider {
constructor(public geofence: Geofence, public events: Events, public platform: Platform) {
platform.ready().then(() => {
if (this.platform.is('cordova')) {
geofence.initialize().then(
() => {
console.log('Geofence Plugin Ready');
this.addGeofences();
},
(err) => console.log(err)
)
}
});
}
addGeofences() {
// options describing geofence
let fences = [
{
id: 'beerstore',
latitude: 45.349094,
longitude: -80.031466,
radius: 20,
transitionType: 1,
notification: {
id: 1,
title: 'Beer Store',
text: 'You are near the Beer Store.',
openAppOnClick: true
}
},
{
id: 'wellingtons',
latitude: 45.349094,
longitude: -80.031466,
radius: 20,
transitionType: 1,
notification: {
id: 2,
title: 'Wellingtons',
text: 'You are near Wellingtons.',
openAppOnClick: true
}
}
]
this.geofence.addOrUpdate(fences).then(
() => console.log('Geofences added'),
(err) => console.log('Geofences failed to add')
);
this.geofence.onTransitionReceived().subscribe((data) => {
console.log(data);
this.events.publish('transition:recieved');
});
}
}