1

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:

  1. From XCode run on target watch (series 5)
  2. Start audio
  3. Screen On: Audio plays via speaker or blueTooth
  4. Screen Off (drop wrist): Background audio plays via speaker or blueTooth

Fail:

  1. Launch app from watch as user would (not run as XCode target)
  2. Start audio
  3. Screen On: App plays via speaker or blueTooth
  4. Screen Off (drop wrist): Background audio dies for speaker or blueTooth output scenarios

As far as I can tell I've:

  1. Set the background capabilities correctly
  2. 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!

Erik Peterson
  • 105
  • 1
  • 1
  • 6

0 Answers0