[notification] iOS: toActiveNotification force-unwraps notificationsMap, crashing on any action tap after the app was terminated

Aperta Adatta ai principianti
#3,533 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
ios, swift
Ambito
mobile

Direzione di ricerca

Inizia in plugins/notification/ios/Sources/NotificationHandler.swift, in corrispondenza di toActiveNotification, quindi esamina i suoi chiamanti didReceive(response:) e willPresent(notification:). Verifica che la richiesta di notifica fornisca i campi fondamentali quando notificationsMap è vuoto ed esegui i test iOS del plugin delle notifiche, se disponibili. Il lavoro è completato quando le notifiche pianificate aperte dopo la terminazione dell’app non causano più arresti anomali e i suoni o gli allegati memorizzati rimangono disponibili quando presenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

platform: ios plugin: notification type: bug
Describe the bug

toActiveNotification force-unwraps an in-memory dictionary that is empty in the exact case a scheduled notification is designed for:

https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/ios/Sources/NotificationHandler.swift

func toActiveNotification(_ request: UNNotificationRequest) -> ActiveNotification {
    let notificationRequest = notificationsMap[request.identifier]!   // 💥

notificationsMap is populated only by saveNotification, at schedule time, in the current process. A notification scheduled hours earlier and delivered after iOS has terminated the app finds it empty, and the force-unwrap traps.

That is the normal case for any scheduled reminder — the whole point of Schedule.at is that it survives the app not running — and the only case for an action tap forwarded from a paired Apple Watch.

Both callers reach it:

  • didReceive(response:) — user taps the notification or one of its action buttons
  • willPresent(notification:) — notification arrives while the app is foreground
Reproduction
  1. sendNotification with schedule: Schedule.at(...) a few minutes out
  2. Force-quit the app (or let iOS terminate it)
  3. When the notification fires, tap it

The app relaunches and immediately crashes instead of delivering the action.

Suggested fix

Nothing the caller needs actually requires the map. id, title, body and actionTypeId all come from the UNNotificationRequest, which is always present; only sound and attachments came from the map, and both degrade cleanly:

let stored = notificationsMap[request.identifier]
return ActiveNotification(
  id: Int(request.identifier) ?? -1,
  title: request.content.title,
  body: request.content.body,
  sound: stored?.sound ?? "",
  actionTypeId: request.content.categoryIdentifier,
  attachments: stored?.attachments
)

Behaviour is unchanged whenever the entry exists. The same file already uses the safe if let form a few lines earlier in willPresent, so this reads as an oversight rather than a deliberate invariant.

Full tauri info output

Plugin version 2.3.3; also present on v2 HEAD as of today. Reproduced on an iOS 26 simulator with tauri-cli 2.9.5.

Stack trace

Crash on relaunch in toActiveNotification, via didReceive(response:).

Additional context

I have been running this as a vendored patch for a few weeks and it has been stable. Happy to open a PR if useful.

Lingua principale
Rust
Stelle
1.8k
Fork
637
Merge medio
5g 3h
PR unite (30g)
36

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tauri-apps/plugins-workspace

Tutte le issue di tauri-apps/plugins-workspace

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.