问题
I'm testing my app on device (a soundboard) and it crashes with a EXC_BAD_ACCESS
, I have use Breakpoints and the error came from [AVAudioSession privateBeginInterruption]
The crash happens following this pattern:
- The app is launched, we see the main menu
- A main menu button is pressed and a soundboard view is loaded (push), some buttons are pressed here and sounds are played.
- Return to main menu (
[self.navigationController popViewControllerAnimated:YES];
) - App enters background
- When app enters foreground and the menu button of the soundboard is pressed the app crashes.
I have no idea what is happening here, I have installed CrashLytics and it only said:

Maybe the audio session gets released from memory and the app tries to access to it and fail?
The audio session is initialised in viewDidLoad
// Initialize audio session
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error: nil];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
In viewDidUnload
I have
[[AVAudioSession sharedInstance] setDelegate: nil];
Any hints?
Thanks!
回答1:
The crash happens because you had set the delegate of session to your controller in this line
[[AVAudioSession sharedInstance] setDelegate: self];
but didn't implemented the required delegate method (interruption one)
either remove the delegate setting line or implement the delegate method to solve crash
来源:https://stackoverflow.com/questions/15015300/app-crashes-with-avaudiosession-privatebegininterruption