Reputation: 2249
My app crashes when I tap either volume button. In my view controller, I am calling setActive
on AVAudioSession.sharedInstance()
and when the user taps a button I play a song with AVAudioPlayer
. In this view controller, whenever a volume button is pressed, wether the player is playing or not, the app crashes with EXC_BAD_ACCESS
. I have seen an error message in the debugger occasionally complaining about key-value observing for outputVolume
.
Any ideas why my app is crashing?
A CLUE: There are two ways I can get to the view controller that is causing the crash. One way causes the crash and the other does not. Either way I am pushing the view controller on to the navigation controller in the same way.
Upvotes: 2
Views: 526
Reputation: 833
Have you added something similar? :
let audioSession = AVAudioSession.sharedInstance()
audioSession.addObserver(self, forKeyPath: "outputVolume",
options: NSKeyValueObservingOptions.new, context: nil)
if you did, then you need to override this method and do whatever you need in it :
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "outputVolume"{
}
}
Upvotes: 2