React-native-push-notification: Clear local notifications not working with "ongoing" notification

Created on 23 Jan 2020  路  4Comments  路  Source: zo0r/react-native-push-notification

I am creating a local notification like so:

pushNotification.localNotification(
  {
    "message" : "Connected to MAP",

    "autoCancel"  : false,
    "id"          : "12345",
    "ongoing"     : true,
    "playSound"   : false,
    "vibrate"     : false
  }
);

And attempting to clear it like so:

pushNotification.cancelLocalNotifications(
  {
    "id"  : "12345"
  }
);

However, the notification will not clear. This seems like a simple enough use case. Am I doing something wrong?

Most helpful comment

I had the exact problem. Setting the repeatType parameter to a string solved the problem for me. I am not sure about the reason this occurs.

PushNotification.localNotification({
    id: (UserData.lastid - 1).toString(),
    message: this.props.data.label,
    ongoing: true,
    repeatType: 'minute'
});

PushNotification.cancelLocalNotifications({ id: activeProcess.id.toString() });

All 4 comments

I have been struggling with this problem today too. The problem is that RNPushNotificationHelper.cancelScheduledNotification try to find the notification from scheduledNotificationsPersistence, and if notification was already fired is not there by the time. The method that must by called is clearLocalNotification with the id as a parameter.
There is also a problem with this method. If it is used to cancel a notification that was created with a tag, it can't cancel it (Because the method in Android for cancel this kind of notifications is cancel(tag, id), not cancel(id), which is the method that is called from clearLocalNotification).

having same problem... anyone found any solution?

I had the exact problem. Setting the repeatType parameter to a string solved the problem for me. I am not sure about the reason this occurs.

PushNotification.localNotification({
    id: (UserData.lastid - 1).toString(),
    message: this.props.data.label,
    ongoing: true,
    repeatType: 'minute'
});

PushNotification.cancelLocalNotifications({ id: activeProcess.id.toString() });

I had the exact problem. Setting the repeatType parameter to a string solved the problem for me. I am not sure about the reason this occurs.

PushNotification.localNotification({
    id: (UserData.lastid - 1).toString(),
    message: this.props.data.label,
    ongoing: true,
    repeatType: 'minute'
});

PushNotification.cancelLocalNotifications({ id: activeProcess.id.toString() });

You saved my life

Was this page helpful?
0 / 5 - 0 ratings