How to add custom actions to iOS push and local notifications in SwiftUI
Learn how to let users respond to notifications without opening the app.
06 Oct 2025 · 4 min read
By default, an iOS notification just shows an alert, and tapping it opens the app. But we can also make notifications interactive by adding custom actions, for example, letting users mark a task as done, snooze a reminder, or open the app directly from the notification.
In this article, we'll look at how to create, register, and handle these actions using SwiftUI.
Let's jump in.

What are notification actions?
Notification actions are the buttons that appear below a notification's text. When a users taps on an action, depending on how we configure the action, the app can either run code silently in the background or open into the foreground if the user should see something. This makes actions perfect for lightweight interactions like "Mark as done" or "Later", without disrupting the user.
To add custom actions to a notification, we need to:
- Define and register custom actions & categories at launch
- Request notification permission (alert, sound, badge)
- Implement the delegate method to handle the user’s chosen action
- Assign category identifiers when scheduling local or sending remote notifications
Let's go through these steps.
Defining and registering categories and actions
Each notification action is represented by UNNotificationAction (or UNTextInputNotificationAction for inline replies). Actions are grouped into categories, represented by UNNotificationCategory.
Here's how we can define and register actions:
class NotificationsService {init() {registerActions()}private func registerActions() {let doneAction = UNNotificationAction(identifier: NotificationAction.done.rawValue,title: "Done", options: [])let notThirstyAction = UNNotificationAction(identifier: NotificationAction.notThirsty.rawValue,title: "Not thirsty", options: [])let category = UNNotificationCategory(identifier: NotificationCategory.drinkingReminder.rawValue,actions: [doneAction, notThirstyAction], intentIdentifiers: [], options: .customDismissAction)UNUserNotificationCenter.current().setNotificationCategories([category])}}enum NotificationCategory: String {case drinkingReminder}enum NotificationAction: String {case donecase notThirsty}
If we do want the app to open when a button is tapped, we can add the .foreground option when defining the action.
Asking for notification permission
At app level, we create our service and ask the user for notification permission:
@mainstruct NotificationActionsApp: App {private var notificationsService = NotificationsService()var body: some Scene {WindowGroup {ContentView().onAppear {notificationsService.requestAuthorization()}}}}class NotificationsService {...func requestAuthorization() {UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, _ inprint("Notifications authorized: \(granted)")}}}
Handling responses
When the user taps an action, the system launches our app (in the background if needed) and calls the delegate.
To keep all notification handling centralized, we can register our service to be the delegate:
class NotificationsService: NSObject, UNUserNotificationCenterDelegate {override init() {super.init()registerActions()UNUserNotificationCenter.current().delegate = self}...func userNotificationCenter(_ center: UNUserNotificationCenter,didReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {switch response.actionIdentifier {case NotificationAction.done.rawValue:print("User tapped Done")case NotificationAction.notThirsty.rawValue:print("User tapped Not thirsty")default:break}completionHandler()}}
Attaching the category to a notification
Now we can use the actions in a notification. To use it on a local notification, we set the categoryIdentifier on UNMutableNotificationContent to tell the system which set of actions to display for that notification:
let content = UNMutableNotificationContent()content.title = "Stay hydrated"content.body = "It's time for a glass of water"content.sound = .defaultcontent.categoryIdentifier = NotificationCategory.drinkingReminder.rawValue
When the notification is delivered, iOS looks up that category and automatically shows the corresponding action buttons.
We can schedule the notification as usual:
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)try await UNUserNotificationCenter.current().add(request)
To use the category on a remote notification, the server can include the identifier in the payload.
{"aps": {"alert": {"title": "Stay hydrated","body": "It's time for a glass of water"},"sound": "default","category": "drinkingReminderCategory"}}



Newsletter
Like to support my work?
Say hi
Related tags
Articles with related topics
Latest articles and tips



