React-native-push-notification: Cancel local notifications is not working - iOS

Created on 11 Oct 2017  路  8Comments  路  Source: zo0r/react-native-push-notification

  • React Native: 0.48
  • Plugin version: 3.0.1

Tried both, the cancelLocalNotifications({ id }) with a notification object as:

PushNotification.localNotificationSchedule({
        id,
        title,
        message,
        date: moment().toDate(),
        largeIcon: 'app_icon',
        smallIcon: 'app_icon',
        color: 'blue',
        userInfo: {
            id
        }
    })

Also, tried cancelAllLocalNotifications() without success.

I can confirm that it is working for Android but not for iOS.

Stale

Most helpful comment

This is the version that worked for me on Android + iOS (with cancel...):

      PushNotification.localNotificationSchedule({
        id: ''+recordID, // must be id of type STRING so that the cancel will work on android
        userInfo: {
          id: ''+recordID, //IMPORTANT!! adding the userInfo, so that the cancel will work!
        },
        number:0, // must have this otherwise it fails.
        data: {
          recordID: recordID,
        },
        message: message,
        date: someDate,
      });

later on:

      PushNotification.cancelLocalNotifications({id: ''+recordID}); // must be id of type STRING so that the 

cancel will work on android

All 8 comments

This is the version that worked for me on Android + iOS (with cancel...):

      PushNotification.localNotificationSchedule({
        id: ''+recordID, // must be id of type STRING so that the cancel will work on android
        userInfo: {
          id: ''+recordID, //IMPORTANT!! adding the userInfo, so that the cancel will work!
        },
        number:0, // must have this otherwise it fails.
        data: {
          recordID: recordID,
        },
        message: message,
        date: someDate,
      });

later on:

      PushNotification.cancelLocalNotifications({id: ''+recordID}); // must be id of type STRING so that the 

cancel will work on android

@EyalSi Confirmed working on Android. Will update after testing on iOS

Thank @EyalSi <3 Important thing is the **id** for cancel must be **String**. Then I solved this issue
PushNotification.cancelLocalNotifications({id: ''+recordID});

Works on iOS.

it is not working foe me. my functions are like this:-

const localNotification = (fromUserName, data, orderId) => {
PushNotification.localNotification({
id: ''+orderId,
autoCancel: true,
largeIcon: JointDeliveryLogoIcon,
smallIcon: JointDeliveryLogoIcon,
bigText: You got a message for (OrderId:-${orderId}),
subText: "",
number:0,
vibrate: true,
vibration: 300,
userInfo: {
id: ''+orderId,
},
color: "green",
title: ${fromUserName},
message: Message:- ${data},
playSound: true,
soundName: 'default',
});
};

const cancelLocalNotifications = (notificationId) => {

console.warn('notification id gettinggggggg=====', notificationId)

PushNotification.cancelLocalNotifications({
  id: ''+notificationId
});

anybody please help me

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings