How to Delete already sent Remote push notification with firebase in iOS?

Viewed 4065

I sending push notification to device but need to delete this already sent push notification after 1 hour. Can i achieve this anyway?

3 Answers

Ohh. Nice question. You can cancel the schedule notification only and if its not already sent. if its already sent to user you can't do cancel.

However, if you want your push notification not to get seen by inactive users then you can set up an auto-expiration time in your notification, these notifications get deleted automatically after a certain span of time.

To implement this, time-to-live is set on Android as an expiration time in seconds, while on iOS it is set as an expiration date

When server send your notification via APNS server using the APNS endpoint, the APNS will return you some data as a payload, you will get the notification identifier as a apns-id key in the response header

Store that apns-id value in your database table at the server side.

After 1 hour, you can delete that notification from the device's notification center by sending another request to APNS by Passing the apns-id value in the request header.

You can set 'content-available' = 1 for silence your delete notification too.

More information: https://stackoverflow.com/a/55646607/2776008

Unfortunately, it is not possible to cancel push notifications once they have been sent. But you can always cancel the messages that are scheduled for delivery ahead of time.

To avoid the regret of sent push notification, make sure you review it carefully before you hit that ‘send’ button. I suggest not only proof-reading the text, but also going through targeting settings.

Related