So, I’ve been doing research on this topic and trying some workarounds with no success for some time: how are we supposed to unsubscribe events set on the local notifications plugin? The app I’m working on has to notify the user a few minutes before the time they should take their medicine. So I’m scheduling a notification and re-scheduling it when they tap the “Reschedule” action button. Inside my schedulePushNotification function, I have this, which applies to the cases where the meds should be taken every X hours (user defined).
/push-service.ts
schedulePushNotification(id, date : Date, message: string, repeat = -1){
(...)
//Handle the action button click
this.localNotifications.on('reschedule').subscribe((res) => {
this.schedulePushNotification(id, new Date(date.getTime() + repeat*1000), message, repeat);
});
this.localNotifications.schedule({
id: id,
text: message,
trigger: {at: datetime},
actions: [{id: 'reschedule', title: 'Schedule next dosis'}, {id: 'cancel', title: 'Cancel'}],
foreground: true
});
(...)
I’ve left only the relevant parts. This is the case when the notification should repeat. The variable datetime is calculated in the removed parts.
The issue is, I never unsubscribe. So everytime a notification with repetition is set, this subscribes another time, building a crescent amount of notifications to arrive in the next one - not to mention that if I click the button during the exact minute. From the documentation ( https://github.com/katzer/cordova-plugin-local-notifications ), there is supposed to be an “on” and an “un” method, but “un” does not exist. Looks like it has been removed.
Tl;dr: how do I unsubscribe events from the Local Notifications plugin now?
1 post - 1 participant