React-native-push-notification: CancelLocalNotifications doesn't work on Android in a new version

Created on 4 Jan 2021  路  12Comments  路  Source: zo0r/react-native-push-notification

Bug

Faced with an issue after update to a newest version: react-native-push-notification": "^7.0.0"
When i creating scheduled notifications and trying to cancel it - it creates anyway and i can't cancel it.
For iOS it works fine, but for scheduling notifications i'm using there PushNotificationIOS.addNotificationRequest, for android i'm using localNotificationSchedule.

Environment info

"react-native": "0.62.1",
@react-native-community/push-notification-ios": "^1.8.0",
Library version: 7.0.0

Steps To Reproduce

  1. PushNotification.localNotificationSchedule() with delay for 5 seconds
  2. then call cancelLocalNotifications with ids of scheduled notifications

Most helpful comment

Hi @Dallas62 ,

I was able to reproduce the same issue if I create a scheduled notification with id as null, but If I generate a random ID then the notifications were canceled properly. I believe it has something to do with generating the notification ID automatically.

{ id: parseInt(Math.random()*1000000000, 10).toString(), title: 'Hello', message: 'World', }

The above code worked for me.

All 12 comments

Hi @atrofimenko

Can you share some code ?
Unable to reproduce.

Please also refer to the documentation:
https://github.com/zo0r/react-native-push-notification#1-cancellocalnotifications

Regards,

I have the same issue after I updated from V6.1.3 to V7.0.0.
I scheduled several notifications like this.

PushNotification.localNotificationSchedule({
...
// id
id: id,
userInfo: {id: id},
...
});

Then I canceled before it was fired, however, the scheduled notifications were still fired.
This is my cancelation code.

PushNotification.cancelLocalNotifications({id: '123'});
PushNotification.cancelLocalNotifications({id: '124'});
PushNotification.cancelLocalNotifications({id: '125'});
PushNotification.cancelLocalNotifications({id: '126'});

(Because I schedule 4 notifications with static ids which are 123 to 126.)

Hi @HyeonjuPark

Can you tell me what's the type of id in userInfo.id ?

@Dallas62 All ids are string type.

@HyeonjuPark You have this issue on Android ? I'm not able to reproduce it 馃槙

I have the same problem in Android, notifications are not being canceled and they still return in PushNotification.getScheduledLocalNotifications()

Hi @MaiconGilton
Again, can you provide a reproducible exemple?
I still not able to reproduce it.
Regards

Hi @Dallas62 ,

I was able to reproduce the same issue if I create a scheduled notification with id as null, but If I generate a random ID then the notifications were canceled properly. I believe it has something to do with generating the notification ID automatically.

{ id: parseInt(Math.random()*1000000000, 10).toString(), title: 'Hello', message: 'World', }

The above code worked for me.

I'm sorry for not responding on time but @anishsrinivasan solution worked for me as well. Thanks dude!

@Dallas62 I found that my @react-native-push-notification-ios/push-notification-ios version was 1.7.3 which does not support removePendingNotificationRequests. After I upgraded it to 1.8.0 it worked.

Hi @HyeonjuPark
https://github.com/zo0r/react-native-push-notification/blob/master/CHANGELOG.md#700-2020-12-23
The first breaking change contains the informations in the PR, resulting in this package.json
https://github.com/zo0r/react-native-push-notification/blob/master/package.json#L27
Regards

Hi guys,

I'm trying to create id with methods above but they don't work for me:

    PushNotification.localNotification({
      id: parseInt(Math.random()*1000000000, 10).toString(),
      channelId: 'channel-@' + id,
      title: title,
      message: text,
      ongoing: ongoing,
      allowWhileIdle: true,
      actions: ['Complete'],
      playSound: false,
      invokeApp: false,
      autoCancel: false,
    });

and canceling with:

export default function finishNote(notificationId) {
    PushNotification.cancelLocalNotifications({id: parseInt("845715191", 10).toString()})
}

Have anyone else still this problem or is it just me?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nguyenvanphuc2203 picture nguyenvanphuc2203  路  3Comments

cidevant picture cidevant  路  3Comments

TfADrama picture TfADrama  路  3Comments

Benzer1406 picture Benzer1406  路  3Comments

anativ picture anativ  路  3Comments