Stopping Scheduled Push Notification In react native push notifications

1.5k Views Asked by At

I want to stop sending my scheduled notifications if I press a button. Like I want to unschedule / stop /cancel the push notifications which was scheduled earlier and then further Notifications shouldn't come Using Lib https://www.npmjs.com/package/react-native-push-notification My Goal is not cancel notification from notification bar or centre. buT TO Stop this scheduled notification

    PushNotification.localNotificationSchedule({
        channelId: 'channel name',
        date: new Date(Date.now()),
        title: 'title',
        message: 'message',
        repeatType: 'day',

    });
1

There are 1 best solutions below

2
On BEST ANSWER

I haven't verified below code but should work as suggested in plugin github issues page

const id = 1;

PushNotification.localNotificationSchedule({
    id:  `${id}`
    message: 'My Scheduled Notification Message',
    date: new Date(Date.now() + (5 * 1000))
  })

PushNotification.cancelLocalNotifications({ id: `${id}` })

Link to issue