evollu / react-native-fcm

react native module for firebase cloud messaging and local notification
MIT License
1.73k stars 682 forks source link

destroy notification - remove notification from notification center #886

Open windydang26 opened 6 years ago

windydang26 commented 6 years ago

when user using app. if notify arrive i have been show local notification but then i dont want this noti show in list notification (swipe down from statusbar) any solution?

windydang26 commented 6 years ago

FCM.removeDeliveredNotification(id) not working for me

evollu commented 6 years ago

FCM.removeAllDeliveredNotifications

windydang26 commented 6 years ago

I have been trying all function of FCM (cancel, cancelAll, remove, removeAll) but not working. If i using them immediate willPresent not working, but when i use them at other moment it working.

evollu commented 6 years ago

can you elaborate the scenario? you want to receive the notification, show the banner and clear it from try right away?

windydang26 commented 6 years ago

Thank @evollu, I mean is if i am staying current screen and have notify of current screen i just want show banner now, but i don't want notify exist in notifications center. Can u help me?

windydang26 commented 6 years ago
    case NotificationType.WillPresent:
        FCM.cancelAllLocalNotifications();
        FCM.removeDeliveredNotification(notif.id);
        FCM.cancelLocalNotification(notif.id);

my code not working

evollu commented 6 years ago

@windydang26 try add a timeout of 2 seconds? notification hasn't been created at that time point. BTW FCM.cancelAllLocalNotifications(); removes recurring/delayed notification schedule, which is not related to your use case

lovekothari123 commented 6 years ago

I am using this both but not working
componentWillMount(){ FCM.removeDeliveredNotification() FCM.cancelAllLocalNotifications() console.log("Setp_Details_CompountWillMount_Called here") } i want to stop notf. only in one screen what should i do for that

lightman73 commented 5 years ago

@evollu Sorry, resurrecting old issue so that we don't have too many open ones.

I can't seem to be able to remove a single notification with FCM.removeDeliveredNotification(notifId).

FCM.removeAllDeliveredNotifications() works fine, though.

To give you some more info, here's the snippet I'm using to test the removal :

handleNotification(notif) {
    console.log('  - New notification received: ');
    console.log(JSON.stringify(notif, null, 2));
    console.log('---------------------------------------------');
    sleep(30000).then( () => {
        console.log(' ----- removing all delivered notifications')
        FCM.removeDeliveredNotification("mynotif")
    })
    …
}

(sleep is a simple arrow function which takes a delay in milliseconds and fires a promise after that delay, so I expect the notification to sit in the notification center for 30 secs and then be removed)

The app is obviously open or in background, otherwise the notification handler and thus the sleep promise wouldn't be fired.

The notification payload is :

{
    "message": {
        "token" : "fy...V7k",
        "apns" : {
            "headers" : {
                "apns-priority" : "5",
                "apns-collapse-id" : "myapnsid",
            },
        },
        "android" : {
            "priority" : "normal",
            "notification": {
                "tag" : "myandroidtag",
            }
        },
        "data" : {
            "id" : "mynotif",
        },
        "notification" : {
            "title" : "Test notif",
            "body" : "Test notif body 999",
        }
    }
}

Note, I'm using FCM v1 API and thus payload, since I can't seem to be able to have the collapsing (via apns-collapse-id under iOS, tag under Android) work otherwise.

Everything is working fine, collapsing, silent notifications, everything, but I can't find a way to remove a single, particular notification. It looks like removeDeliveredNotification can't match the delivered notifications to the passed notificationId...