From 32c103ad4282c9268b7c0b15383f91891e7b2b13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bj=C3=B6rkert?= Date: Mon, 30 Mar 2026 22:27:16 +0200 Subject: [PATCH] Fix alarm sound session activation failures in background Use .duckOthers instead of empty options when configuring the audio session for alarm playback. The empty options created a non-mixable session that conflicted with the background silent audio player (which uses .mixWithOthers), causing setActive(true) to fail with "Session activation failed" when the app was in the background. --- LoopFollow/Controllers/AlarmSound.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/LoopFollow/Controllers/AlarmSound.swift b/LoopFollow/Controllers/AlarmSound.swift index ba131bc4f..c4ded4d44 100644 --- a/LoopFollow/Controllers/AlarmSound.swift +++ b/LoopFollow/Controllers/AlarmSound.swift @@ -88,7 +88,7 @@ class AlarmSound { audioPlayer = try AVAudioPlayer(contentsOf: soundURL) audioPlayer!.delegate = audioPlayerDelegate - try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: []) + try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: .duckOthers) try AVAudioSession.sharedInstance().setActive(true) audioPlayer?.numberOfLoops = 0 @@ -126,7 +126,7 @@ class AlarmSound { audioPlayer = try AVAudioPlayer(contentsOf: soundURL) audioPlayer!.delegate = audioPlayerDelegate - try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: []) + try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: .duckOthers) try AVAudioSession.sharedInstance().setActive(true) // Only use numberOfLoops if we're not using delay-based repeating @@ -184,7 +184,7 @@ class AlarmSound { audioPlayer = try AVAudioPlayer(contentsOf: soundURL) audioPlayer!.delegate = audioPlayerDelegate - try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: []) + try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: .duckOthers) try AVAudioSession.sharedInstance().setActive(true) audioPlayer!.numberOfLoops = 0 @@ -213,7 +213,7 @@ class AlarmSound { audioPlayer = try AVAudioPlayer(contentsOf: soundURL) audioPlayer!.delegate = audioPlayerDelegate - try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: []) + try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: .duckOthers) try AVAudioSession.sharedInstance().setActive(true) // Play endless loops @@ -262,7 +262,7 @@ class AlarmSound { fileprivate static func enableAudio() { do { - try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: []) + try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: .duckOthers) try AVAudioSession.sharedInstance().setActive(true) LogManager.shared.log(category: .alarm, message: "Audio session configured for alarm playback") } catch {