App crashes with AVAudioSession privateBeginInterruption

风格不统一 提交于 2019-12-01 06:32:06

问题


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:

  1. The app is launched, we see the main menu
  2. A main menu button is pressed and a soundboard view is loaded (push), some buttons are pressed here and sounds are played.
  3. Return to main menu ([self.navigationController popViewControllerAnimated:YES];)
  4. App enters background
  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!