Biosopher
Biosopher

Reputation: 616

iOS: How do I capture all error data when an app crashes?

Besides logging all NSExceptions in the main method, where else should I be capturing all error messages? E.g. if my app crashes due to accessing an over-released object, how can I get all the available information about the crash and write it to a local file on a device? I know how to do this in XCode but need to get this info from offsite QA testers.

When these memory errors occur, they don't seem to be caught by the main method.

Upvotes: 4

Views: 3336

Answers (2)

Rob Napier
Rob Napier

Reputation: 299455

Doing this really well is actually quite challenging. You're in the midst of a crash, which means that the system is in an undefined state. Small errors can lead to complete deadlock (if you crash while the heap is locked for instance, and then you try to allocate more memory). Unless you're looking for the learning experience of building and debugging it, you should reuse an existing framework. The best, IMO, is PLCrashReporter, which has gone through many iterations to get to its current state. It even integrates nicely with QuincyKit for crash report management on your own servers (plus several commercial solutions).

If you do decide to write your own (did I mention you shouldn't?), first study PLCrashReporter to see how they're doing it. If I had one most-important-rule, it would be: do as little as you possibly can during the crash, and then handle any complicated processing during the next launch.

Upvotes: 3

borrrden
borrrden

Reputation: 33421

The information in this post will probably help you. Basically, you can set a function in objective-c to be called when an unhanded exception or signal is met

Looks something like this:

NSSetUncaughtExceptionHandler(&HandleException);
signal(SIGABRT, SignalHandler);
signal(SIGILL, SignalHandler);
signal(SIGSEGV, SignalHandler);
signal(SIGFPE, SignalHandler);
signal(SIGBUS, SignalHandler);
signal(SIGPIPE, SignalHandler);

The rest of the post will describe how to set up these methods (HandleException and SignalHandler).

Upvotes: 1

Related Questions