I'm using XCode 11.4, WatchOS 6.2, Swift/UI to build a watch app that plays background audio via speaker or BlueTooth pending user choice. Here are the scenarios:
Pass:
- From XCode run on target watch (series 5)
- Start audio
- Screen On: Audio plays via speaker or blueTooth
- Screen Off (drop wrist): Background audio plays via speaker or blueTooth
Fail:
- Launch app from watch as user would (not run as XCode target)
- Start audio
- Screen On: App plays via speaker or blueTooth
- Screen Off (drop wrist): Background audio dies for speaker or blueTooth output scenarios
As far as I can tell I've:
- Set the background capabilities correctly
- Set Session category and activated prior to playing audio
do {
try session.setCategory(AVAudioSession.Category.playback,
mode: .default,
policy: useBlueTooth ? .longFormAudio : .default,
options: [])
} catch _ {
fatalError("AudioSession Failed.")
}
session.activate(options: []) { (success, error) in
guard error == nil else {
print("Audio Session Activation Error: \(error!.localizedDescription)")
// Handle the error here.
return
}
}
What might cause this failing behavior when not launched via XCode? Advice on how to debug/fix please. Thanks!