From a7dc50356d37b1d27fab58ff6ee359ce66940374 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 17 Feb 2023 11:48:30 +0100 Subject: [PATCH] Stop playing sounds when stopping app --- LeCountdown/LeCountdownApp.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/LeCountdown/LeCountdownApp.swift b/LeCountdown/LeCountdownApp.swift index d7d3d4d..404c0ef 100644 --- a/LeCountdown/LeCountdownApp.swift +++ b/LeCountdown/LeCountdownApp.swift @@ -30,6 +30,8 @@ struct LeCountdownApp: App { self._registerBackgroundRefreshes() } + @Environment(\.scenePhase) var scenePhase + #if os(iOS) @Environment(\.horizontalSizeClass) private var horizontalSizeClass #endif @@ -57,6 +59,14 @@ struct LeCountdownApp: App { .onAppear { self._onAppear() } + .onChange(of: scenePhase) { newPhase in + switch newPhase { + case .inactive: + Conductor.maestro.stopSoundIfPossible() + default: + break + } + } } }