3

I know in Android, there is a pretty reliable built-in system for notifying me of crashes that happen. They almost immediately write the stack trace and some other info into a Google doc. it works tremendously well.

I started researching the same thing for ios, and I am not finding anything similar that is equally effective. I read this article: Xcode storyboard: Why does the iPad storyboard show iPhone sized views?

but I am not sure if this is still the case. Could anyone recommend me what to use for crash reports that happen on user devices?

Thanks!

Community
  • 1
  • 1
GeekedOut
  • 16,905
  • 37
  • 107
  • 185
  • Is this for testing, or public release? – glenn sayers Aug 16 '12 at 14:58
  • @glennsayers this is going to be for a public release of the app – GeekedOut Aug 16 '12 at 15:00
  • I know that you're looking for a live crash-reporting system, but Apple does record and aggregate crash reports from your applications, and you can access these within iTunes Connect at any time. – Brad Larson Aug 16 '12 at 17:56
  • iTunes Connect only shows crashes IF the user agrees to send anonymous usage data to Apple on setup time, or since iOS5 somewhere deep in the settings. By far most users don't agree! And also only a few crashes once they happened an unknown amount of times. You can refresh the list also only once a day. And most of the times (for weeks or months) it will hardly show anything! Don't rely on iTunes connect! It is the only way to get crashes do to exhaustive memory consumptions or if startup/shutodnw etc. is taking too long. – Kerni Aug 19 '12 at 12:04

3 Answers3

3

What you can do is create a new uncaught exception handler, then register it via NSSetUncaughtExceptionHandler. That way, each crash can be intercepted just before the kill, and you can log it / save it somewhere to upload.

(I've personally used the method described in this link : http://cocoawithlove.com/2010/05/handling-unhandled-exceptions-and.html)

Valentin Rocher
  • 11,667
  • 45
  • 59
  • thank you - as I am reading the cocoawithlove link, it says that this is meant only for testing. Does apple not allow this in a production app? Or were you able to keep that code in a production app? – GeekedOut Aug 16 '12 at 15:18
  • Apple didn't say anything about it when we released the app on the AppStore, so I suppose they allow it. – Valentin Rocher Aug 21 '12 at 13:59
3

I'm using Flurry with an uncaughtExceptionHandler and GTMStackTrace

The exception handler can look like this:

void uncaughtExceptionHandler(NSException *exception) 
{
    @try 
    {
        NSString *fullBacktrace = GTMSBStackTraceFromException(exception);
        NSMutableString *backtrace = [NSMutableString stringWithUTF8String:""];
        NSArray *backtraceArray = [fullBacktrace componentsSeparatedByString:@"\n"];
        for (id entry in backtraceArray) 
        {
            NSRange testRange = [entry rangeOfString:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]];
            if (testRange.length)
            { 
                [backtrace appendString:entry];    
            }
        }

        NSCharacterSet *whitespaces = [NSCharacterSet whitespaceCharacterSet];
        NSPredicate *noEmptyStrings = [NSPredicate predicateWithFormat:@"SELF != ''"];

        NSArray *parts = [backtrace componentsSeparatedByCharactersInSet:whitespaces];
        NSArray *filteredArray = [parts filteredArrayUsingPredicate:noEmptyStrings];
        NSString *strippedBacktrace = [filteredArray componentsJoinedByString:@" "];   
        [FlurryAnalytics logError:@"uncaughtExceptionHandler"
                          message:[NSString stringWithFormat:@"%@", strippedBacktrace ? strippedBacktrace : @"no matching backtrace"]
                        exception:exception];
    }
    @catch (NSException *exception) 
    {
        NSLog(@"whoa!  could not handle uncaught exception!");
        [FlurryAnalytics logError:@"uncaughtExceptionHandler"
                          message:@"no matching backtrace"
                        exception:exception];
    }
}

Testflight has a good crash log too.

zeiteisen
  • 7,078
  • 5
  • 50
  • 68
  • thanks, do you mean you use flurry not just for analytics of usership, but they help in error-reporting too? – GeekedOut Aug 16 '12 at 15:14
  • Yes. Flurry is some kind of (evil?) mighty data collector. But its service is great. – zeiteisen Aug 16 '12 at 15:18
  • lol..what do you mean? I use it for my android app, but it has been pretty useless. How do you use it on ios? – GeekedOut Aug 16 '12 at 15:34
  • btw, I have not used uncaughtExceptionHandler before. Is it supposed to live somewhere in particular and only be written once? Or is it supposed to live in every controller? – GeekedOut Aug 16 '12 at 15:39
  • Just add in applicationDidFinishLaunching: this line NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); and the method above to the Appdelegate – zeiteisen Aug 16 '12 at 15:50
2

Setting an uncaughtexception handler will only give you a subset of crash reports, and also the details of the reports you get that way are very limited. You don't get stack traces of all threads, you don't get the stacktrace of the exception where the crash really happened, and you don't get the line numbers of your code where the crash happened. In addition you don't get any crash reports caused by signal handlers.

In addition you should NOT run any objective-C code once a crash occurs since it is not async-safe. See this article for more information about it: Reliable Crash Reporting

If posted some more details on what you can do as answers to the following questions: Crash analytics and reporting for iOS and iOS crash log catch, debug info.. Catch and send via email to the Dev team

Community
  • 1
  • 1
Kerni
  • 15,241
  • 5
  • 36
  • 57