Interactive Notifications
Configure standard and custom interactive notification categories with action buttons for iOS push notifications.
Interactive notifications allow users to take actions directly from the notification without opening your app. You can add buttons to notifications that perform specific actions when tapped.
Standard Interactive Notifications
Airship provides built-in interactive notification types with pre-configured action buttons. See Built-In Interactive Notification Types for available types and button configurations.
To use a standard interactive notification type, specify the category ID in your push payload. The notification will automatically display the appropriate action buttons.
Custom Interactive Notification Categories
You can define custom notification categories with specific actions tailored to your app’s needs.
Airship reserves category IDs prefixed with ua_. Any custom categories with that prefix will be ignored.
Create a Custom Category
Create custom notification category
// Define an action for the category
let categoryAction = UNNotificationAction(
identifier: "category_action",
title: "Action!",
options: [.authenticationRequired, .foreground, .destructive]
)
// Define the category
let category = UNNotificationCategory(
identifier: "custom_category",
actions: [categoryAction],
intentIdentifiers: [],
hiddenPreviewsBodyPlaceholder: "Sensitive Content Hidden",
options: []
)
// Register the custom category
Airship.push.customCategories = [category]// Define an action for the category
UNNotificationAction *categoryAction = [UNNotificationAction
actionWithIdentifier:@"category_action"
title:@"Action!"
options:(UNNotificationActionOptionForeground |
UNNotificationActionOptionDestructive |
UNNotificationActionOptionAuthenticationRequired)];
// Define the category
UNNotificationCategory *category = [UNNotificationCategory
categoryWithIdentifier:@"custom_category"
actions:@[categoryAction]
intentIdentifiers:@[]
options:UNNotificationCategoryOptionNone];
// Register the custom category
UAirship.push.customCategories = [NSSet setWithArray:@[category]];Action Options
When creating notification actions, you can specify the following options:
.foreground/UNNotificationActionOptionForeground: Opens the app when the action is tapped.destructive/UNNotificationActionOptionDestructive: Displays the action button in red (use for destructive actions like “Delete”).authenticationRequired/UNNotificationActionOptionAuthenticationRequired: Requires the device to be unlocked before the action can be performed
Hidden Preview Placeholder
The hiddenPreviewsBodyPlaceholder parameter specifies placeholder text that will be shown instead of the notification’s body when the user has disabled notification previews for your app. This is useful for sensitive content that shouldn’t be displayed in notification previews.
Handle Action Responses
When a user taps an action button, handle the response in your notification callback:
Handle action responses
Airship.push.onReceivedNotificationResponse = { response in
if response.actionIdentifier == "category_action" {
// Handle the action
}
}UAirship.push.onReceivedNotificationResponse = ^(UNNotificationResponse *response) {
if ([response.actionIdentifier isEqualToString:@"category_action"]) {
// Handle the action
}
};Related Documentation
Categories