为啥 deleteRecording 崩溃(AVAudioRecorder,iOS)?

Posted

技术标签:

【中文标题】为啥 deleteRecording 崩溃(AVAudioRecorder,iOS)?【英文标题】:Why deleteRecording crashed (AVAudioRecorder, iOS)?为什么 deleteRecording 崩溃(AVAudioRecorder,iOS)? 【发布时间】:2012-01-19 11:44:05 【问题描述】:

[录音机删除录音]; 30 次运行良好,但在 31 次左右就崩溃了。

0   libobjc.A.dylib                 0x3266fc98 objc_msgSend + 16
1   Foundation                      0x328c203c -[NSError dealloc] + 36
2   CoreFoundation                  0x30d2dc3c -[NSObject(NSObject) release] + 24
3   Foundation                      0x328e687c -[NSFilesystemItemRemoveOperation dealloc] + 36
4   Foundation                      0x328bc7b2 -[NSOperation release] + 38
5   CoreFoundation                  0x30d2e19a CFRelease + 62
6   CoreFoundation                  0x30d30eb4 _CFAutoreleasePoolPop + 140
7   Foundation                      0x328abbae NSPopAutoreleasePool + 2
8   Foundation                      0x3293a908 __NSThreadPerformPerform + 620
9   CoreFoundation                  0x30da0a72 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
10  CoreFoundation                  0x30da2758 __CFRunLoopDoSources0 + 376
11  CoreFoundation                  0x30da34e4 __CFRunLoopRun + 224
12  CoreFoundation                  0x30d33ebc CFRunLoopRunSpecific + 224
13  CoreFoundation                  0x30d33dc4 CFRunLoopRunInMode + 52
14  GraphicsServices                0x31896418 GSEventRunModal + 108
15  GraphicsServices                0x318964c4 GSEventRun + 56
16  UIKit                           0x355b9d62 -[UIApplication _run] + 398
17  UIKit                           0x355b7800 UIApplicationMain + 664
18  AppName                         0x000020f6 main (main.m:16)
19  AppName                         0x00002050 start + 44

【问题讨论】:

看起来你过度释放你的对象。但是如果没有你发布任何代码,就很难回答 我自己不发布任何东西,只是使用 AVAudioRecorder 框架。也许记录器在删除发生之前已经解除分配?但我保留了录音机,我无意取消分配它... 我讨厌进入后台线程的框架方法,用它们进行调试很繁重。 你真的应该发布一些代码。就目前而言,任何人都不太可能帮助您解决这样的问题 这里的 AVAudioRecorder 也有同样的问题... 【参考方案1】:

我发现当 deleteRecording 尝试删除不存在的文件时会发生这种情况。所以在调用它之前检查文件是否存在:

if ([[NSFileManager defaultManager] fileExistsAtPath:self.recorder.url.path]) 
        if (![self.recorder deleteRecording])
            NSLog(@"Failed to delete %@", self.recorder.url);

这一定是 AVAudioRecorder 的错误。

【讨论】:

以上是关于为啥 deleteRecording 崩溃(AVAudioRecorder,iOS)?的主要内容,如果未能解决你的问题,请参考以下文章

为啥不在应用程序崩溃时启动外部崩溃转储处理程序?

*应该*崩溃的简单Objective-C过度发布不会崩溃。为啥?

为啥我的 prepareForSegue 崩溃

为啥我的 [UIScrollView removeFromSuperview] 崩溃了?

应用程序崩溃。为啥?

为啥崩溃会随着“僵尸对象”而消失?