Class

UNUserNotificationCenter

The central object for managing notification-related activities for your app or app extension.

Overview

Use the shared UNUserNotificationCenter object to manage all notification-related behaviors in your app or app extension. Specifically, use this object to:

To handle incoming notifications and notification-related actions, create an object that adopts the UNUserNotificationCenterDelegate protocol and assign it to the delegate property of this object. Always assign an object to the delegate property before performing any tasks that might interact with that delegate. It is a programmer error to assign a delegate object after calling methods that return information to the delegate.

You may use the shared user notification center object simultaneously from any of your app's threads. The object processes requests serially in the order they were initiated.

Topics

Getting the Notification Center

class func current() -> UNUserNotificationCenter

Returns the shared user notification center object for your app or app extension.

Receiving Notifications and Handling Actions

var delegate: UNUserNotificationCenterDelegate?

The object that processes incoming notifications and notification-related actions.

protocol UNUserNotificationCenterDelegate

The interface for handling incoming notifications and notification-related actions.

Managing Settings and Authorization

func requestAuthorization(options: UNAuthorizationOptions = [], completionHandler: (Bool, Error?) -> Void)

Requests authorization to interact with the user when local and remote notifications are delivered to the user's device.

var supportsContentExtensions: Bool

A Boolean value indicating whether the current device supports notification content extensions.

struct UNAuthorizationOptions

Constants for requesting authorization to interact with the user.

Registering the Notification Categories

func setNotificationCategories(Set<UNNotificationCategory>)

Registers your app’s notification types and the custom actions that they support.

func getNotificationCategories(completionHandler: (Set<UNNotificationCategory>) -> Void)

Retrieves the app’s currently registered notification categories.

Scheduling and Canceling Notification Requests

func getPendingNotificationRequests(completionHandler: ([UNNotificationRequest]) -> Void)

Returns a list of all notification requests that are scheduled and waiting to be delivered.

func removePendingNotificationRequests(withIdentifiers: [String])

Unschedules the specified notification requests.

func removeAllPendingNotificationRequests()

Unschedules all pending notification requests.

Managing Delivered Notifications

func getDeliveredNotifications(completionHandler: ([UNNotification]) -> Void)

Returns a list of the app’s notifications that are still displayed in Notification Center.

func removeDeliveredNotifications(withIdentifiers: [String])

Removes the specified notification requests from Notification Center.

func removeAllDeliveredNotifications()

Removes all of the app’s delivered notifications from Notification Center.

Handling Errors

struct UNError

Error constants for notifications.

let UNErrorDomain: String

The error domain for notifications.

Relationships

Inherits From

Conforms To

See Also

Notification Management

protocol UNUserNotificationCenterDelegate

The interface for handling incoming notifications and notification-related actions.

class UNNotificationSettings

The object for managing notification-related settings and the authorization status of your app.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software