We keep the app running in the background using WKExtendedRuntimeSession (with self-care background mode). The audio session is configured with .playback category, .longFormAudio policy, and .mixWithOthers + .duckOthers options, and activated while the app is in the foreground. For audio playback we use AVAudioPlayer(data:) with in-memory WAV data for metronome ticks, and AVSpeechSynthesizer for voice counts. We also run a continuous near-silent AVAudioPlayer loop to keep the audio session active between beeps.
Two specific questions:
Is WKExtendedRuntimeSession the correct mechanism for this use case, or should we use something else? (We can't use HKWorkoutSession since users run this alongside other workout apps.)
Does .longFormAudio work correctly with .mixWithOthers, or are those contradictory?
Topic:
App & System Services
SubTopic:
Health & Fitness
Tags: