Native app clear specific notification

0
I can see an option to clear all delivered notifications using this:  How to clear a specific notification? For example, there is a category of notifications in which we want to clear all notifications before sending a new one from that category. That means notifications from other categories should stay there unless the user clears them. Can we attach some sort of ID to a notification and later clear it anytime? I am using local notifications that are displayed by display notification activity in nanoflow
asked
1 answers
0

Looks like it should be possible. You can add a NotificationId when you schedule a notification, and cancel the scheduled notification with the ‘CancelScheduledNotification’ action from NativeMobileResources v 3.1.0 . For delivered notifications it looks like some custom work.

[EDIT]

I tested this and you can create this by adding a NotificationID parameter to the DisplayNotification JSA, then duplicate the ClearAllDeliveredNotification action, also add a NotificationID and change it to this: 


// BEGIN EXTRA CODE
const idList = [];
// END EXTRA CODE

/**
 * Clears all delivered notifications from notification tray
 * @param {string} notificationID
 * @returns {Promise.<void>}
 */
export async function ClearDeliveredNotificationByID(notificationID) {
	// BEGIN USER CODE
    // Documentation https://github.com/zo0r/react-native-push-notification
    const isIOS = Platform.OS === "ios";
    if (NativeModules &&
        ((isIOS && !NativeModules.RNCPushNotificationIOS) || (!isIOS && !NativeModules.RNPushNotification))) {
        return Promise.reject(new Error("Notifications module is not available in your app"));
    }
    if(notificationID){
        idList[0] = notificationID;
    }
    PushNotification.removeDeliveredNotifications(idList);
    return Promise.resolve();
	// END USER CODE

Just for clarity, this is how to add the NotificationID parameter in the DisplayNotification JSA code

 }
      if (notificationID) {
        notification.id = notificationID;
    }

 

answered