Modifies the content of remote notifications before they are delivered to the user.
- iOS 10.0+
UNNotification class provides the entry point for a Notification Service app extension, which lets you customize the content of a remote notification before it is delivered to the user. A Notification Service app extension does not present any UI of its own. Instead, it is launched on demand when a notification of the appropriate type is delivered to the user’s device. You use this extension to modify the notification’s content or download content related to the extension. For example, you could use the extension to decrypt an encrypted data block or to download images associated with the notification.
You do not create instances of the
UNNotification class yourself. Instead, the Xcode template for a Notification Service Extension target contains a subclass for you to modify. Use the methods of that subclass to implement your app extension’s behavior. When a remote notification for your app is received, the system loads your extension and calls its
did method only when both of the following conditions are met:
The remote notification is configured to display an alert.
The remote notification’s
apsdictionary includes the
mutable-contentkey with the value set to
did method performs the main work of your extension. You use that method to make any changes to the notification’s content. That method has a limited amount of time to perform its task and execute the provided completion block. If your method does not finish in time, the system calls the
service method to give you one last chance to submit your changes. If you do not update the notification content before time expires, the system displays the original content.
As for any app extension, you deliver a Notification Service app extension class as a bundle inside your app. The template provided by Xcode configures the
Info file automatically for this app extension type. Specifically, it sets the value of the NSExtensionPointIdentifier key to
com and sets the value of the NSExtensionPrincipalClass key to the name of your
For information about how to create and schedule remote notifications using the Apple Push Notification service (APNs), see Local and Remote Notification Programming Guide.