Remove notifications & TTL
How to remove notifications from a user's device.
When sending push notifications, the user's device needs to be turned on and have a network connection to receive the message. If the device is not turned on, then you have the ability to set a wait time for how long the Google (FCM), Apple (APNS), and other push services will wait for the device to come back online before discarding the message. See Time To Live (ttl) below for details.
Once the push notification is received by the device, there is little that can be done to remove it but you have some options to replace/collapse it from view.
Notification replacing
This refers to the ability to replace a notification already received by the user with another notification.
Mobile Push - All mobile push notifications received on a device will be available for the user to click within the Notification Center. Notifications generally stay in the Notification Center for around 7 days if not interacted with, and this is set by the operating system. Some operating systems will automatically group notifications together and you have some control over this as well. See Notification Grouping for details.
You have the ability to replace notifications for mobile apps with the Collapse ID. Android also provides custom options to remove notifications using code while iOS does not. See below Remove notifications without replacing for details.
Web Push - For Chrome, Edge, and Firefox web push notifications that have already been received are automatically replaced with the newest web push received. This means older notifications that have not been clicked and which are stored in the device's Notification Center are replaced by the newer notifications received. Safari does not provide notification collapse functionality.
For example, Notification 1 is sent and received, but the subscriber does not click it. Notification 2 is sent and received. Notification 1 is removed and replaced with Notification 2.
You can set the Web Push Topic to display more than 1 web push notification at a time. See Web Push Topic for details.
If sending frequent notifications, especially on something that is changing like "breaking news", you may want to consider notification collapsing. Collapsing is replacing older or irrelevant notifications with newer ones; solving the problem of notifications piling up and overwhelming users whenever they are not actively checking their new notifications.
Collapse ID
Collapsing works by only showing the latest notification of a given type, 'collapsing' aka 'removing' the other unread notifications of the same type that come before it. For instance, if you have a weather app and want to update users on the latest weather, you probably want to replace those notifications with whatever is the latest one.
The way notification collapsing works is by adding a collapse_id
to particular types of notifications you are sending that you want collapsed together (E.g. the id is weather_update
or breaking news
). Then, every time you wish to have a future notification override previous ones, you add the same collapse_id
to it. If your app sends three notifications, the following would happen:
-
Sent 1:41pm: "A storm looks like it's approaching. Better grab an umbrella!"
-
Sent 2:20pm: "The storm in your area seems to be clearing up. Expect sunshine soon."
-
Sent 2:44pm: "The storm has moved north and the sun will shine the rest of today!"
If a user does not open their device until 4pm, they would only see the third notification. If the user opened their device at 2pm and 4pm, they would see the first notification, and then at 4pm see the third notification.
collapse_id
does not work with Data Notifications on iOS, the notification must show data in this case to remove it from view.
Web push topic
The Web Push Topic is any string value you can set when sending push from the dashboard or web_push_topic
API parameter.
If you do not specify the web_push_topic
, each notification will be replaced by a newer notification. If you do specify web_push_topic
, you can choose which notifications will be replaced and which notifications will stack.
For example:
- Notification 1 sent with
web_push_topic
: "breaking-news" - Notification 2 sent with
web_push_topic
: "breaking-news"
Notification 2 will replace Notification 1.
- Notification 3 sent with
web_push_topic
: "sports" - Notification 4 sent with
web_push_topic
: "weather"
Notification 2, 3 and 4 will all either be left on the screen or docked in the Notification Center.
Remove notifications without replacing
In some cases, you may want notifications to "self-destruct" or be removed from the device without replacing them with others. There are a couple options for this:
Android: Within the Notification Service Extension, use the native Android API setTimeoutAfter
method to remove the notification after a certain amount of time.
iOS: Apple provides the native removeDeliveredNotifications(withIdentifiers:)
method and getDeliveredNotifications(completionHandler:)
method to target the expired notifications and remove them.
Android & iOS: You can send Data & Background Notifications which do not display any content to the user but can remove notifications.
- Android: run code in Service Extensions to remove the notification.
- iOS: the notifications in the Notification Center are tied to the Badge Count. As long as you have at least 1 badge set, you can send a notification setting the badge count to 0 to remove all notifications for your app.
Web: There is not a way to remove web push notifications without collapsing.
Time to live
This is the amount of time a notification will be held by the Google (FCM), Apple (APNs), Huawei (HMS) servers if the subscriber's device does not have an internet connection. OneSignal sets this to 3 days by default. This means if the device does not connect to the internet within 3 days, the message will not be sent to that device. The maximum amount of time is 2,419,200
seconds or 28 days.
If the TTL value is 0
, APNs/FMC treats the notification as if it expires immediately and does not store the notification or attempt to redeliver it if the device is not connected to a network. HMS requires a minimum value of 1
.
For example, if you set TTL to 3 hours (10800 seconds) and my device does not have internet connection for 3 hours and 1 second or longer, I will not get the notification.
TTL does not remove the notification from the device once it has been received.
Time to Live can be set within the dashboard when sending push messages or using the API ttl
property.
iOS Limitation - Apple will only store the most recent notification sent to a device on the APNs servers. If you send multiple notifications to an iOS device while it is offline, only the most recent notification will show when the device comes back online. More information on this in Apple's APNs Overview.
FAQ
How many notifications can be stored in the Notification Center?
On Chrome, a maximum of 3 notifications are displayed at any time, even if the other notifications are not related to your site or from OneSignal. This means you can only show 3 categories of notifications to your user, not counting for other notifications that might be displayed at that time.
On Firefox on Windows, many more notifications can be shown at a time (6+).
On Firefox on Mac, and Safari on Mac, only one notification can be shown at a time, even if the other notifications are not related to your site or from OneSignal. Notifications also disappear quickly within 5 seconds and this time is not customizable.
On Chrome/Firefox on Android, multiple notifications can be shown at a time.
Can you remove web push notifications without collapsing them?
There is not a way to remove web push notifications without collapsing.
Updated 2 months ago