Files
ForumMobile/ios/App/NotificationService/COMMUNICATION_NOTIFICATIONS.md
2026-06-21 05:00:55 -05:00

54 lines
2.5 KiB
Markdown

# Communication Notifications (avatar + app-icon badge)
The Notification Service Extension (`NotificationService.swift`) turns incoming
pushes into **communication notifications** on iOS 15+: a large circular avatar
(the sending network's photo) with the app icon badged in the corner.
## How it works
1. The server (`frm.so`, `notifications.js`) sets `mutableContent: 1` and adds to
the push payload:
- `imageUrl` — a PNG of the network's logo (the server rasterizes SVG logos to
PNG via `sharp`, since iOS can't render SVG avatars).
- `senderName` — the network name (used as the conversation title; falls back
to the notification's own title).
- `isGroup` — `true`, so iOS uses the group-avatar style.
2. The extension downloads `imageUrl`, builds an `INSendMessageIntent` with the
image as the sender/group avatar, donates it, and returns
`content.updating(from: intent)`.
3. On iOS 14 the extension falls back to attaching the image as a plain thumbnail.
## Required setup (both pieces are mandatory)
Two things must be in place or the avatar silently won't render:
### 1. `NSUserActivityTypes` declares the intent (already in this repo)
`INSendMessageIntent` is declared under `NSUserActivityTypes` in **both**
`App/Info.plist` and `NotificationService/Info.plist`. Without this the donation
fails with *"Donating intent 'INSendMessageIntent' is not supported by this
extension"* and the communication styling never applies.
### 2. Communication Notifications capability (one-time, in Xcode — cannot be scripted)
The capability must be registered on the provisioning profile, not just present
in the entitlements file:
1. Open `ios/App/App.xcworkspace` in Xcode.
2. Select the **App** target → **Signing & Capabilities** → **+ Capability** →
add **Communication Notifications**.
- This adds `com.apple.developer.usernotifications.communication` to
`App.entitlements` (already in this repo) and, crucially, enables the
capability on the App ID / provisioning profile. Requires a paid Apple
Developer account.
3. If the avatar still doesn't appear, add the same capability to the
**NotificationService** target as well.
4. Rebuild and reinstall on a device (communication notifications don't reliably
render on the Simulator).
## Notes
- Requires iOS 15.0+ for the communication style; older versions get the plain
attachment fallback automatically.
- The app's deployment target is currently 14.0, so no bump is required.