Customize Notifications
How to customize push notification presentation, badges, quiet time, and foreground display behavior.
iOS Notification Options
By default, the Airship SDK will request alert, badge, and sound notification options for remote notifications. This can be configured by setting notification options before enabling user notifications.
await Airship.push.iOS.setNotificationOptions([
"alert",
"badge",
"sound"
])Provisional Authorization
Apps can request provisional authorization along with the usual notification options. When requesting provisional authorization, apps do not need to prompt the user for permission initially, and notifications will be delivered in a non-interruptive manner to the Notification Center until the user explicitly chooses to keep delivering messages either prominently or quietly.
await Airship.push.iOS.setNotificationOptions([
"alert",
"badge",
"sound",
"provisional"
])Foreground Presentation Options
When a push is received in the foreground on iOS, how the notification is displayed to the user is controlled by foreground presentation options. By default, the SDK will not set any options so the notification will be silenced.
await Airship.push.iOS.setForegroundPresentationOptions([
"banner",
"list",
"sound"
])Badges
The badge on iOS presents a counter on top of the application icon. You can control this directly through Airship.
// Set badge number
await Airship.push.iOS.setBadgeNumber(20)
// Reset badge
await Airship.push.iOS.setBadgeNumber(0)
// Enable auto-badge
await Airship.push.iOS.setAutobadgeEnabled(true)When using auto-badge, only modify the badge value through Airship methods to ensure the value stays in sync.
Quiet Time
Quiet time allows you to suppress notifications during specific hours. Notifications are still received but won’t be displayed to the user during the quiet time window.
// Set quiet time hours
await Airship.push.iOS.setQuietTime({
startHour: 22,
startMinute: 0,
endHour: 7,
endMinute: 0
})
// Enable quiet time
await Airship.push.iOS.setQuietTimeEnabled(true)Quiet time is only supported on iOS.
Android Foreground Notifications
By default, push notifications received while the app is in the foreground on Android are displayed to the user. You can control this behavior globally:
// Disable foreground notifications
await Airship.push.android.setForegroundNotificationsEnabled(false)
// Enable foreground notifications
await Airship.push.android.setForegroundNotificationsEnabled(true)Silent Notifications
Silent notifications are push messages that do not present a notification to the user. These are typically used to briefly wake the app from a background state to perform processing tasks or fetch remote content.
We recommend that you thoroughly test your implementation to confirm that silent notifications do not generate any device notifications.
For Android, all push messages are delivered in the background, but default Airship will treat messages without an alert as silent. For iOS, set the content_available property to true in the iOS override object.
Pushes sent with the content_available property (iOS) or without an alert (Android) do not have guaranteed delivery. Factors affecting delivery include battery life, whether the device is connected to WiFi, and the number of silent pushes sent within a recent time period. These metrics are determined solely by iOS/Android and APNs/FCM. Therefore, this feature is best used for supplementing the regular behavior of the app rather than providing critical functionality. For instance, an app could use a silent push to pre-fetch new data ahead of time in order to reduce load times when the app is later launched by the user.
Categories