---
title: "Recipe: change a remote notification before it appears"
description: "Declare one UNNotificationServiceExtension subclass named NotificationService; other Swift files are helpers."
modificationDate: "2026-11-17"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: change a remote notification before it appears

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/notification-service-extension: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

Put an Apple notification service extension's Swift in:

```prompt Change a push notification before it appears
Add an Apple notification service extension to the Exact app in this folder, so that Swift code can change a remote notification before it appears. Use https://github.com/expo/exact/blob/main/docs/recipes/notification-service-extension.md as the source for each step. The Exact checkout has the same page at docs/recipes/notification-service-extension.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. If I did not say what the extension changes in the notification, and what my server sends, ask me before you write code. The extension is for iOS and iPadOS only: macOS, tvOS and watchOS builds refuse the folder, so tell me if the app ships one. It has no Exact runtime, so it cannot run Contract or TypeScript: all its work is Swift.
3. Put the Swift in `modules/apple/notification-service/NotificationService.swift`: one `UNNotificationServiceExtension` subclass named `NotificationService`. Other `.swift` files in the folder are helpers. The build refuses a link or any other visible file there, except a top-level `PrivacyInfo.xcprivacy`.
4. Call the handler exactly once. In `serviceExtensionTimeWillExpire()`, cancel the work and return the best content. On expiry, iOS shows the original notification.
5. In app.ts, grant both notification capabilities in `grants`, as the recipe shows: `device.notifications purpose.notifications` and `device.push`. Keep the app's other grants.
6. If the extension uses a required-reason API, declare an approved reason for it in `modules/apple/notification-service/PrivacyInfo.xcprivacy`. Exact supplies none. If you do not know which reason applies, ask me.
7. Run `bun exact.mjs ios` to build the app with the extension, then `bun exact.mjs verify ios` until it passes. Do not pass `--extensions none`, which excludes the folder. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 8) and report it; do not keep trying.
8. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
9. Tell me what the extension changes, what the build and verify reported, and what I must still do by hand. A device build needs a profile for the App ID `<app id>.notifications` with the app's App Group and shared Keychain group. My server must send a visible alert whose `aps` dictionary has `"mutable-content": 1` and an alert title and body. A tap opens only the top-level `navigate`. The checks send no push, so the extension stays untested until I send one to an iPhone.
```

```text
modules/apple/notification-service/NotificationService.swift
```

Declare one `UNNotificationServiceExtension` subclass named `NotificationService`;
other Swift files are helpers. It has no Exact runtime and cannot run Contract or
TypeScript. The inventory is every non-dot `.swift` file plus top-level `PrivacyInfo.xcprivacy`,
excluding `target` subtrees. Links in the folder, `modules/apple` or `modules` and
non-UTF-8 names are refused. Entries use bytewise UTF-8 order; other visible files
are refused.

Grant both notification capabilities in `app.ts`:

```ts
export const grants = 'device.notifications purpose.notifications\ndevice.push';
```

The build derives the target. It writes
`PlugIns/ExactNotificationService.appex`, bundle id `<app id>.notifications`, and
principal class `ExactNotificationService.NotificationService`. It inherits the app's
version, minimum iOS, App Group and shared Keychain group. A device build needs a
profile for that App ID with the same groups. Put its required-reason declarations in
`modules/apple/notification-service/PrivacyInfo.xcprivacy`; the build validates and
merges them into the extension. Declare an approved reason for every required-reason
API it uses; Exact supplies none.

APNs invokes it only for a visible alert whose `aps` dictionary has
`"mutable-content": 1` and an alert title and body:

```json
{
  "aps": {
    "alert": { "title": "Encrypted", "body": "Open to read" },
    "mutable-content": 1
  },
  "navigate": "/messages/42"
}
```

Call the handler exactly once. On expiry, iOS shows the original notification;
`serviceExtensionTimeWillExpire()` should cancel work and return the best content.

An ordinary iOS or iPadOS build packages the folder. `--extensions none` or a list
without `notifications` excludes it; other Apple platforms refuse it. A source edit
starts a new binary cohort. Packaging verifies the recorded inventory into a private
snapshot; a tool already requiring a binary uses it to name the changed member. Otherwise
the folder is ordinary app source to freshness, watches, captures and scanners. An ignored
file may stale an iOS drive once; a service-only edit rebuilds web and stales a no-hatch
Windows build, as any edit under `modules/` does.

A tap opens only top-level `navigate` as an untrusted local location. Exact reads no
other key. Data-only wake, content extensions, critical-alert or filtering
entitlements, arrival events and Contract or TypeScript execution remain
unavailable. Live Activity push-to-start is `exactActivities()`'s, not the extension's
([contract grammar](https://exact.expo.dev/reference/contract-grammar/components-and-actions.md#live-activities-startactivity-updateactivity-endactivity)).
