Framework

UserNotifications

Push user-facing notifications to the user's device from a server, or generate them locally from your app.

Overview

User-facing notifications communicate important information to users of your app, regardless of whether your app is running on the user's device. For example, a sports app can let the user know when their favorite team scores. Notifications can also tell your app to download information and update its interface. Notifications can display an alert, play a sound, or badge the app's icon.

The notification interface is displayed on the lock screen and on the Home screen of an iOS device.

You can generate notifications locally from your app or remotely from a server that you manage. For local notifications, the app creates the notification content and specifies a condition, like a time or location, that triggers the delivery of the notification. For remote notifications (also known as push notifications), you use one of your company's servers to generate notifications, and Apple Push Notification service (APNs) handles the delivery of those notifications to the user's devices.

Use this framework to:

  • Define the types of notifications that your app supports.

  • Define any custom actions associated with your notification types.

  • Schedule local notifications for delivery.

  • Process already delivered notifications.

  • Respond to user-selected actions.

Topics

First Steps

Asking Permission to Use Notifications

Ask the user's permission to display alerts, play sounds, or badge the app’s icon in response to a notification.

Notification Management

class UNUserNotificationCenter

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

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.

Remote Notifications

Generate notifications from your company's servers, and deliver those notifications using APNs.

Setting Up a Remote Notification Server

Set up a server to generate notifications and push them to user devices.

Registering Your App with APNs

Communicate with APNs and receive a unique device token that identifies your app.

Notification Requests

Create delivery requests for local notifications, and access the content of delivered local and remote notifications.

Scheduling a Notification Locally from Your App

Create and schedule notifications from your app when you want to get the user's attention.

class UNNotificationRequest

A request to schedule a local notification, which includes the content of the notification and the trigger conditions for delivery.

class UNNotification

The data for a local or remote notification that was delivered to your app.

Notification Content

Modify and examine the payload of a notification.

class UNMutableNotificationContent

The editable content for a notification.

class UNNotificationContent

The uneditable content of a notification.

class UNNotificationAttachment

A media file associated with a notification.

class UNNotificationSound

The sound played when a notification is delivered.

struct UNNotificationSoundName

A string providing the name of a sound file.

Triggers

Define the trigger conditions for delivering notifications. Detect when a remote notification was delivered from APNs.

class UNCalendarNotificationTrigger

A trigger condition that causes a notification to be delivered at a specific date and time.

class UNTimeIntervalNotificationTrigger

A trigger condition that causes a notification to be delivered after the specified amount of time elapses.

class UNLocationNotificationTrigger

A trigger condition that causes a notification to be delivered when the user's device enters or exits the specified geographic region.

class UNPushNotificationTrigger

A trigger condition that indicates the notification was sent from Apple Push Notification Service (APNs).

class UNNotificationTrigger

The common behavior for subclasses that trigger the delivery of a local or remote notification.

Notification Categories and User Actions

Define the types of notifications that your app supports, and define how users can respond.

Declaring Your Actionable Notification Types

Differentiate your notifications and add action buttons to the notification interface.

class UNNotificationCategory

A type of notification that your app supports and the custom actions to display with it.

class UNNotificationAction

A task to perform in response to a delivered notification.

class UNTextInputNotificationAction

An action that can accept user-typed text.

Notification Responses

Handling Notifications and Notification-Related Actions

Respond to user interactions with the system’s notification interfaces, including handling your app's custom actions.

class UNNotificationResponse

The user’s response to an actionable notification.

class UNTextInputNotificationResponse

The user’s response to an actionable notification, including any custom text that the user typed or dictated.

Notification Service App Extension

Use a notification service app extension to modify the content of a notification before it's delivered to your app.

Modifying Content in Newly Delivered Notifications

Modify the payload of a remote notification before it's displayed on the user’s iOS device.

class UNNotificationServiceExtension

An object that modifies the content of a remote notification before it's delivered to the user.

Entitlements

APS Environment Entitlement

The environment for push notifications.

Key: aps-environment
APS Environment (macOS) Entitlement

The environment for push notifications in macOS apps.

Key: com.apple.developer.aps-environment