Commit 204e3cc
authored
Fix alarm sound session activation failures in background (#596)
* 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.
* Gate alarm session option on app state and add notification fallback
Limit the .duckOthers option to the only state where legacy options: []
fails: background without Silent Tune holding a mixable session alive.
In foreground or with Silent Tune, restore options: [] so the alarm
continues to dominate other audio with no behavioral change for those
users.
In that same fail-prone state, plumb the alarm's soundFile through
AlarmManager.sendNotification so the system-delivered notification
carries the user's configured alarm sound as an audible fallback. In
other states the notification keeps .default to avoid an echo with the
in-app AVAudioPlayer loop.
* Ladder audio session options instead of a binary switch
Replace the static .duckOthers/[] choice with a fallback ladder that tries
options in order [] → .duckOthers → .mixWithOthers and stops at the first
that activates. In background without Silent Tune the [] candidate is
skipped, since iOS denies it there (cannotInterruptOthers, 560557684).
Each attempt is logged with the iOS error code so failures are visible
in the field.
Revert the notification soundFile path; notifications stay on .default
and the in-app AVAudioPlayer remains the only source of the alarm tone.
Also drops the redundant enableAudio() call from play() — the do-block
already activates the session.1 parent b68598b commit 204e3cc
1 file changed
Lines changed: 33 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
92 | | - | |
| 91 | + | |
93 | 92 | | |
94 | 93 | | |
95 | 94 | | |
| |||
116 | 115 | | |
117 | 116 | | |
118 | 117 | | |
119 | | - | |
120 | | - | |
121 | 118 | | |
122 | 119 | | |
123 | 120 | | |
| |||
126 | 123 | | |
127 | 124 | | |
128 | 125 | | |
129 | | - | |
130 | | - | |
| 126 | + | |
131 | 127 | | |
132 | 128 | | |
133 | 129 | | |
| |||
145 | 141 | | |
146 | 142 | | |
147 | 143 | | |
148 | | - | |
149 | | - | |
| 144 | + | |
150 | 145 | | |
151 | 146 | | |
152 | 147 | | |
| |||
184 | 179 | | |
185 | 180 | | |
186 | 181 | | |
187 | | - | |
188 | | - | |
| 182 | + | |
189 | 183 | | |
190 | 184 | | |
191 | 185 | | |
| |||
213 | 207 | | |
214 | 208 | | |
215 | 209 | | |
216 | | - | |
217 | | - | |
| 210 | + | |
218 | 211 | | |
219 | 212 | | |
220 | 213 | | |
| |||
260 | 253 | | |
261 | 254 | | |
262 | 255 | | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
270 | 283 | | |
| 284 | + | |
271 | 285 | | |
272 | 286 | | |
273 | 287 | | |
| |||
0 commit comments