ios - iOS 7-捕获内部库错误异常

标签 ios exception exception-handling ios7 crash

我正在使用AVAudioPlayer(在计算器应用程序中)在点击按钮时运行音频文件。我在iOS7上面临的问题是,每当真正快速点击按钮时,音频播放器的播放方法就会在AVAudioPlayer中导致内部错误。这是代码部分

@try
{
    if(self.allAudioPlayers == nil)
    {
        [self initializePlayer];
    }

    AVAudioPlayer *player = [self grabPlayer];

    if(player != nil)
    {
        NSLog(@"Playing....");
        [player play];       //Crashing Here
    }
    else
    {
        NSLog(@"Player nil");
    }
}
@catch (NSException *exception)
{
    NSLog(@"playCalculatorTickSound Exception: %@", [exception description]);
    NSLog(@"Call Stack: %@", [exception callStackSymbols]);
}

一旦收到此问题ResolveOpageRef,现在我收到的问题是_platform_memmov $ VARIANT $ CortexA8。

这是调用堆栈的另一张图片(它从不相同,并且在某种程度上有所不同)

我的异常处理代码没有捕获异常,因为它是内部错误。无论如何,有没有抓住这个机会,使应用程序不会崩溃?

我正在使用线程来调用此方法。我不确定,但可能是多个线程试图同时读取文件,并且[播放器播放]正在处理线程同步,但未能这样做。

提前致谢

最佳答案

感谢大家的意见。我认为问题已经解决。这是更新的代码。似乎线程是主要问题。 AVAudioPlayer的播放方法不能同时很好地处理多个线程。我不知道它在内部如何工作,但我认为它正在管理某种队列(从调用堆栈中判断)。我在主线程上执行了它,现在工作正常。

 @try
    {
        if(self.allAudioPlayers == nil)
        {
            [self initializePlayer];
        }

        AVAudioPlayer *player = [self grabPlayer];

        if(player != nil)
        {
            NSLog(@"Playing....");

            dispatch_async(dispatch_get_main_queue(), ^{

                [player play];
            });
        }
        else
        {
            NSLog(@"Player nil");
        }
    }
    @catch (NSException *exception)
    {
        NSLog(@"playCalculatorTickSound Exception: %@", [exception description]);
        NSLog(@"Call Stack: %@", [exception callStackSymbols]);
    }

另外,由于有了Any suggestions on how to handle this crash in CGImageDestinationFinalize?,我可以将我的注意力转移到线程问题上。

关于ios - iOS 7-捕获内部库错误异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20856032/

相关文章:

ios - 文档从未出现在 "Recent"选项卡中

c# - 如何在 C# 中进行异常处理和跟踪

c# - Database.ExecuteSqlCommand - 捕获 SQL 异常

Ruby - 执行已过期

c# - 处理源自线程的错误的标准方法

asp.net - 写入事件日志时出现 System.Security.SecurityException

ios - 如何使用Webview将Facebook like按钮添加到iOS应用程序?

ios - 使用 Swift 和 Storyboard 在动态 TableViewCell 中创建 UILabels

ios - 带有 UIActivity 指示器的 UIAlert View - 仅显示事件一次

Java:为什么我不能在比较器中抛出异常?