【问题标题】:Crashed: AVAudioSession Notify Thread EXC_BAD_ACCESS崩溃:AVAudioSession 通知线程 EXC_BAD_ACCESS
【发布时间】:2018-08-27 16:56:18
【问题描述】:

我遇到了 EXC_BAD_ACCESS KERN_INVALID_ADDRESS 崩溃。是 AVFAudio 原生 SDK 问题还是我遗漏了一些需要处理的问题?

请查看 crashlytics 屏幕截图以了解更多信息。

我通过调用初始化了 AVAudioSession:

- (BOOL)prepareAudioSession {

BOOL success = [[AVAudioSession sharedInstance] setActive:NO error: nil];
if (!success) {
    NSLog(@"deactivationError");
}

success = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord 
withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
if (!success) {
    NSLog(@"setCategoryError");
}

success = [[AVAudioSession sharedInstance] setActive:YES error: nil];
if (!success) {
   NSLog(@"activationError");
}

return success;

}   

然后我调用 [[AVAudioSession sharedInstance] availableInputs] 来检查蓝牙连接设备的数量

【问题讨论】:

  • 这看起来像是内存管理错误。如果没有代码示例,真的很难说它是什么。您可能正在尝试访问已被 ARC 删除的值。可以发一段代码吗?
  • 感谢@juniorgarcia 的帮助。我已经在原始问题中发布了我的代码。顺便说一句,我无法重现那次崩溃,但我在织物上看到了它。另外,我使用仪器来解决问题,但没有发现任何内存泄漏。
  • 查看回溯并找到代码中的最后一帧。那将是崩溃的导火索。如果堆栈跟踪中没有您的代码,那么您正在以触发崩溃的方式配置 AV。没有更多证据,很难说。

标签: ios objective-c avaudiosession


【解决方案1】:

根据堆栈跟踪,看起来您订阅了 KVO 更改或某些通知,例如 AVAudioSessionRouteChangeNotification 或 MPVolumeViewWirelessRouteActiveDidChangeNotification,但您的对象(侦听器)在没有 removeObserver/取消订阅的情况下被释放。

在 iOS 9 或更高版本中,NSNotificationCenter 观察者不再需要在被释放时取消注册自身。所以我建议检查 KVO。

【讨论】:

  • 谢谢,ilnal_al。但是我在 appDelegate.m 中初始化了 AVAudioSession,我没有观察到任何通知或 KVO 更改。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-14
  • 1970-01-01
  • 1970-01-01
  • 2013-03-24
  • 2010-11-18
  • 2013-01-07
相关资源
最近更新 更多