0

我已将此代码用作UncaughtExceptionHandler我的应用程序来捕获一些崩溃信息并将其返回给我:

NSArray *callStack = [exception callStackReturnAddresses];
    int i,len = [callStack count];
//  void **frames = new void *[len];
    void **frames = (void**)malloc(len);

    for (i = 0; i < len; ++i) {
        frames[i] = (void *)[[callStack objectAtIndex:i] unsignedIntegerValue];
    }
    char **symbols = backtrace_symbols(frames,len);

    /*
     *  Now format into a message for sending to the user
     */

    NSMutableString *buffer = [[NSMutableString alloc] initWithCapacity:4096];

    NSBundle *bundle = [NSBundle mainBundle];
    [buffer appendFormat:@"Version %@\n\n",[bundle objectForInfoDictionaryKey:@"CFBundleVersion"]];
    [buffer appendFormat:@"Device: %@. OS: %@\n", [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion]];
    [buffer appendString:@"Uncaught Exception\n"];
    [buffer appendFormat:@"Exception Name: %@\n",[exception name]];
    [buffer appendFormat:@"Exception Reason: %@\n",[exception reason]];
    [buffer appendString:@"Stack trace:\n\n"];
    for (i = 0; i < len; ++i) {
        [buffer appendFormat:@"%4d - %s\n",i,symbols[i]];
    }

今天,我收到了一份崩溃报告,与您从 iTunes Connect 获得的报告相比,该报告非常少。它看起来像这样:

0 - 0 CoreFoundation 0x395472a3 + 162
1 - 1 libobjc.A.dylib 0x3343697f objc_exception_throw + 30
2 - 2 CoreFoundation 0x395471c5 + 0
3 - 3 Foundation 0x342ec7cb + 66
4 - 4 myapp 0x0012887d myapp + 424061
5 - 5 myapp 0x001285ed myapp + 423405
6 - 6 myapp 0x0013f1f1 myapp + 516593
7 - 7 libdispatch.dylib 0x3783a11f + 10
8 - 8 libdispatch.dylib 0x378394b7 + 22
9 - 9 libdispatch.dylib 0x3783e1bd + 224
10 - 10 CoreFoundation 0x3951af3b + 1290
11 - 11 CoreFoundation 0x3948debd CFRunLoopRunSpecific + 356
12 - 12 CoreFoundation 0x3948dd49 CFRunLoopRunInMode + 104
13 - 13 GraphicsServices 0x3785b2eb GSEventRunModal + 74
14 - 14 UIKit 0x326cd2f9 UIApplicationMain + 1120
15 - 15 myapp 0x000e72e7 myapp + 156391
16 - 16 myapp 0x000c2530 myapp + 5424 

我使用 atos 来表示报告中的内存地址,但是 3 个地址0x0013f1f1 0x001285ed 0x0012887d只是返回__PRETTY_FUNCTION__.20480 (in myapp) + 101235 __PRETTY_FUNCTION__.20480 (in myapp) + 8047 __PRETTY_FUNCTION__.20480 (in myapp) + 8703,这对我没有帮助。我还能做些什么来至少找到导致崩溃的方法名称吗?

如果没有,有什么我可以添加到我的UncaughtExceptionHandler或在将来的版本中为我提供方法名称的东西吗?我似乎从未收到任何 iTunes Connect 崩溃报告,这就是我选择这条路线的原因。

谢谢

4

1 回答 1

3

一些服务/库可以考虑获得更好的崩溃报告,就像你问的那样。

使用其中之一可以让您忘记未处理异常的复杂性,他们是专家。除非您有兴趣成为该领域的专家,否则我真的建议您选择其中一位。我知道这并不能回答您问题的第一部分,但如果您无法获得答案或想花时间研究它,希望它能提供一些价值。

于 2013-01-15T20:01:27.813 回答