My app works fine when I load it directly from Xcode to my phone via USB but once I load it to TestFlight the sounds no longer play when the app is not in focus or the phone is locked. I've tried every combination of tools available from the support group and from AI! And I'm out of ideas.
app not playing audio when not in focus
import SwiftUI import AVFoundation import UIKit
@main struct RaceTimerAppApp: App { init() { configureAudioSession() }
var body: some Scene {
WindowGroup {
ContentView()
}
}
func configureAudioSession() {
do {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
try AVAudioSession.sharedInstance().setActive(true)
DispatchQueue.main.async {
UIApplication.shared.beginReceivingRemoteControlEvents()
}
print("✅ Audio session configured for background playback.")
print("🎧 Audio category: \(AVAudioSession.sharedInstance().category.rawValue)")
} catch {
print("❌ Failed to set audio session: \(error)")
}
}
}