I have the following code to (re)start AVAudioEngine
wired up to AVAudioEngineConfigurationChangeNotification
:
do {
try self.engine.start()
} catch {
DDLogError("could not start sound engine")
self.soundEnabled = false
return
}
self.engine is defined as
private let engine = AVAudioEngine()
However, I frequently receive crash reports via Crashlytics saying
Fatal Exception: com.apple.coreaudio.avfaudio error 561015905
on the line containing the try self.engine.start()
.
561015905 is AVAudioSessionErrorCodeCannotStartPlaying
and from what I understand, this should be a NSError
error code, not an exception, which should be caught by my blank catch
in the code above. Still, the app just seems to crash at that point. What am I missing?
I know there are situations where the app wakes up in the background where this error can occur and I would be fine with that, as long as I can somehow catch it happening, as I thought I could with do/catch
.