From 96a1885e4dbdd3ba9fc49551d411526b4de6c118 Mon Sep 17 00:00:00 2001 From: Evan Kaloudis Date: Sat, 6 Jun 2026 02:46:52 -0400 Subject: [PATCH] fix(ios): block on NWC Live Activity cleanup at app termination --- ios/zeus/NWCActivityManager.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ios/zeus/NWCActivityManager.swift b/ios/zeus/NWCActivityManager.swift index cf33ed0a1..62607ff68 100644 --- a/ios/zeus/NWCActivityManager.swift +++ b/ios/zeus/NWCActivityManager.swift @@ -36,9 +36,19 @@ import UIKit @objc func endAllActivitiesImmediately() { stopRefreshTimer() activity = nil + + // Synchronous wait so `applicationWillTerminate:` doesn't return + // before ActivityKit's async `end()` lands. iOS gives ~5s before + // SIGKILL; cap at 3s to leave headroom. + let sem = DispatchSemaphore(value: 0) Task.detached(priority: .userInitiated) { await Self.endEveryNWCLiveActivity() - NSLog("[NWCActivity] ended all (immediate)") + sem.signal() + } + if sem.wait(timeout: .now() + 3.0) == .timedOut { + NSLog("[NWCActivity] end-all timed out after 3s") + } else { + NSLog("[NWCActivity] ended all (sync)") } }