Logo for tanaschita.com

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.

Sponsorship logo
Architecture & Design Patterns for iOS
This book is a practical guide to essential architectural principles and design patterns for iOS development. It covers strategies for building maintainable apps with Swift and SwiftUI, including dependency injection, navigation, common patterns, and modularization.
LEARN MORE

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:

  1. Define and register custom actions & categories at launch
  2. Request notification permission (alert, sound, badge)
  3. Implement the delegate method to handle the user’s chosen action
  4. 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 done
case 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:

@main
struct 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, _ in
print("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 = .default
content.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"
}
}
Sponsorship logo
Preparing for a technical iOS job interview
Preparing for a technical iOS Job Interview with over 300 questions & answers. Covering Swift & Objective-C, SwiftUI & UIKit, Combine, HTTP Networking, iOS File System, Core Data, Concurrency with async/await, Security, Automated Testing, Dependency Management, AI & Machine Learning and more.
LEARN MORE
Sponsorship logo
Architecture & Design Patterns for iOS
This book is a practical guide to essential architectural principles and design patterns for iOS development. It covers strategies for building maintainable apps with Swift and SwiftUI, including dependency injection, navigation, common patterns, and modularization.
LEARN MORE
Sponsorship logo
Become a sponsor of tanaschita.com
By publishing an article on different iOS topics every week, tanaschita.com is constantly growing in the developer community and may provide a great audience for you as a sponsor.
CLICK TO LEARN MORE

Newsletter

Image of a reading marmot
Subscribe

Like to support my work?

Say hi

Related tags

Articles with related topics

notifications

swiftui

swift

ios

Registering for push notifications in SwiftUI

Learn how to request notification permissions and register for remote notifications in a SwiftUI app.

01 Jun 2026 · 7 min read

Latest articles and tips

© 2026 tanaschita.com

Privacy policy

Impressum