User Agents

Web browsers and everyday web tech, explained

Notification Extension in iOS Development Explained

· 6 min read · Settings and Privacy

In this article
  1. Background: Why Apple Added Notification Extensions
  2. Types of Notification Extensions
  3. How Notification Service Extension Works
  4. How Notification Content Extension Works
  5. Choosing Between Service and Content Extension
  6. Common Problems and Pitfalls
  7. Security and Privacy Considerations
  8. Alternatives to Notification Extensions
  9. Frequently Asked Questions

A notification extension in iOS development is a separate executable bundle that lets your app modify or customize push notifications before they are displayed to the user. Introduced in iOS 10, notification extensions run as independent processes managed by the system, allowing you to change the notification’s content, add media attachments, or create a custom interface. They are not part of your main app’s binary; instead, they are compiled as separate targets within the same Xcode project.

Background: Why Apple Added Notification Extensions

Before iOS 10, push notifications were plain text with a fixed layout. Developers could only set the alert message, sound, and badge number. Users saw the same generic banner regardless of the app. Apple introduced notification extensions to give developers more control while keeping the system secure. Since the extension runs in its own sandboxed process, it cannot access the main app’s data or user interface, which protects user privacy and prevents malicious code from hijacking the notification flow. The extension is launched on demand by the system, only when a notification arrives, and it has a limited execution time (about 30 seconds for content modifications, less for UI rendering).

Types of Notification Extensions

There are two main types of notification extensions in iOS:

  • Notification Service Extension – runs before the notification is displayed. It can modify the content, decrypt encrypted payloads, or download and attach media files (images, videos, audio). It is used for rich notifications.
  • Notification Content Extension – runs when the user expands a notification. It provides a custom view controller that replaces the default notification interface. This is used for interactive or highly customized notifications, such as a messaging app showing a full chat preview.

Both are declared in the app’s extension point, and you can include both in the same app if needed.

How Notification Service Extension Works

The service extension is triggered after the push notification arrives but before it is shown. The system launches the extension with the original UNNotificationRequest. You override the didReceive(_:withCompletionHandler:) method. Inside, you can:

  1. Modify the notification’s content (e.g., change the title, body, or subtitle).
  2. Decrypt the payload if you sent encrypted data (common for secure messaging).
  3. Fetch media from a remote URL and attach it using UNNotificationAttachment.
  4. Call the completion handler with the modified content, or with the original if you decide not to change anything.

For example, a weather app might send a push with a temperature value in Celsius, and the extension converts it to Fahrenheit based on the user’s locale. Or a news app could attach a thumbnail image to the notification. The extension has its own Info.plist and must be signed with the same team as the main app.

How Notification Content Extension Works

The content extension is used when the user force-touches or long-presses a notification. It provides a custom view controller that you design in Interface Builder. You set the UNNotificationExtensionCategory in the extension’s Info.plist to match the category identifier you send in your push payload. The system instantiates your view controller and passes the notification content via the didReceive(_:) method. You can then update your UI with the data. The extension can also have interactive buttons, similar to notification actions, but they are defined in the extension’s Info.plist rather than the main app. The content extension runs in a reduced-size window; you can set the expanded size using preferredContentSize.

Choosing Between Service and Content Extension

Deciding which extension to use depends on what you need:

  • Use a service extension if you only need to alter the notification content or add media before display. It is simpler and does not require user interaction.
  • Use a content extension if you need a fully custom interface, such as showing a map, a chat bubble, or a progress bar. It only appears when the user expands the notification.
  • You can combine both: the service extension modifies the content, and the content extension displays it in a custom way.

Note that content extensions are not supported on all devices; older iOS versions may fall back to the default notification UI.

Common Problems and Pitfalls

Developers often run into these issues:

  • Extension not being called – Make sure the extension target is included in the app’s build and that the category identifiers match exactly.
  • Media attachment fails – The file must be downloaded to a temporary location and saved with a proper file extension. The system requires the file to be in a local URL, not a remote one.
  • Extension crashes – Because the extension runs in a separate process, any uncaught exception will terminate it silently. Always wrap code in do-catch blocks.
  • Memory limits – The extension has a memory limit (around 30 MB). Downloading large images can cause the extension to be killed.
  • Testing – You cannot test the extension by running the app from Xcode; you must send a real push notification. Use a tool like simctl or a physical device with a push payload that includes the mutable-content flag set to 1.

Security and Privacy Considerations

Notification extensions are sandboxed and cannot access the main app’s keychain or user defaults. They can only access network resources if you have enabled the appropriate entitlements. Because the extension may be invoked when the device is locked, you should avoid displaying sensitive information in the notification body. The system itself redacts the notification preview if the user has disabled previews in settings. Also, the service extension runs even if the app is terminated, so it must be self-contained and not rely on the main app’s state. Apple reviews extensions as part of the app submission; make sure your extension does not attempt to hide or alter system UI.

Alternatives to Notification Extensions

If you only need to display simple rich media, you can use the built-in notification attachments without a service extension – just include the attachments key in the push payload with a URL to an image or video. However, this requires the media to be hosted and accessible; the system downloads it automatically. For custom UI, there is no alternative other than a content extension. If you need to update a live activity, iOS 16 introduced Live Activities with a different mechanism (ActivityKit). For background data updates, you might use background fetch instead of push notifications. But for modifying push content, the notification service extension is the standard and only official way.

Frequently Asked Questions

Do I need a notification extension to show an image in a push notification?

No. You can include an image URL in the attachments key of the push payload, and the system will download and display it automatically. However, if you need to modify the image or add it dynamically based on the user, you need a service extension.

Can I use a notification extension to open my app or trigger actions?

No. Notification extensions only modify the appearance or content of the notification. They cannot launch your app or execute code in the background beyond the extension’s process. To trigger actions, use notification actions (buttons) or deep links in the notification.

How do I test a notification extension?

You need to send a real push notification. In Xcode, you can use the simctl push command to send a payload to the simulator, or use a physical device with a push certificate. Ensure the payload includes "mutable-content":1 for the service extension to be invoked.

What is the difference between a notification extension and an app extension?

An app extension is a broader category that includes today widgets, share extensions, and custom keyboards. Notification extensions are a specific type of app extension that deals with push notifications. They are separate targets but share the same principles of sandboxing and separate processes.

Can I have multiple notification extensions in one app?

Yes, you can have one service extension and one content extension, but you cannot have two of the same type. Each extension must have a unique bundle identifier.

Are notification extensions supported on all iOS devices?

They are supported on iOS 10 and later, which covers most modern devices. However, content extensions require 3D Touch or long-press gestures; devices without those may not show the custom UI.