I have a problem with AVAudioEngine in SpriteKit game - when plugging/unplugging of headphones the engine stops and when the next sound play the app crashes. It is a known bug (or feature?) - with a suggestion to fix it - to use notification center, AVAudioEngine should post notification when it is changing it's states. I have made this code:
let notificationName = Notification.Name("AVAudioEngineConfigurationChange")
NotificationCenter.default.addObserver(self, selector: #selector(self.restartEngine(notification:)), name: notificationName, object: nil)
When I do this:
NotificationCenter.default.post(name: notificationName, object: nil)
My selector gets called. However when I plug/unplug headphones - nothing happens. Swift 3, xcode 8, iOS 9.3 Any suggestions on how to fix it?