Local Notifications: how to unsubscribe event?

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).

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);

                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?

When you subscribe to an observable, it will return a Subscription. Therefore, you can declare a variable of type Subscription like rescheduleSubscription and call unsubscribe() on the variable to unsubscribe the event. The example code is below:

import { Subscription } from 'rxjs';

private rescheduleSubscription: Subscription;

// Handle the action button click
this.rescheduleSubscription = this.localNotifications.on('reschedule').subscribe((res) => {
           // Your logic to handle when action button is clicked here

           // Unsubscribe the event right after the button is clicked to avoid event listener repeating itself