4

I'm using AVAudioSession in an app that only performs audio playback. I'm setting my audioSession's mode and category in applicationDidFinishLaunchingWithOptions:.

let audioSession = AVAudioSession.sharedInstance()

do {
   try audioSession.setMode(AVAudioSessionModeDefault)
   try audioSession.setCategory(AVAudioSessionCategoryPlayback)
}
catch {}

I never set a different mode or category during my app's lifetime, and I activate my audio session when the user taps a play button. In what scenario would either of these methods (setMode:error: and setCategory:error) throw an error? What should I expect to handle in my catch block?

vpetro
  • 83
  • 6

1 Answers1

0

A hypothetical (future?) device with no audio output might throw an invalid audio session category error. Or possibly the OS audio driver has crashed and can't be accessed. Perhaps inform the user that the device can't play audio for some unknown reason.

hotpaw2
  • 68,014
  • 12
  • 81
  • 143