0

I've found that my iOS 5 app is sometimes unexpectedly quited and it does not seem to be due to an uncaught exception, since I've implemented uncaughtExceptionHandler in the app delegate class and I get nothing from there.

If it is because the system is terminating it, it looks like you can only be aware of that if it is in background state: I've read the following line in Apple's documentation.

The applicationWillTerminate: method is not called if your app is currently suspended.

So, if I'm not wrong, you can get the reason why your app is terminated by the system in these cases:

  • App was in background state
  • Low-memory event was triggered

Can I detect more causes of why the app is being terminated, in order to report the issue? Or is it possible that it is not currently being terminated, but moved to background without user interaction?

Thanks

AppsDev
  • 12,319
  • 23
  • 93
  • 186

1 Answers1

2

NSSetUncaughtExceptionHandler() installs a handler for Objective-C exceptions (e.g. trying to access an NSArray item that does not exist). It does not catch the lower level signals like segmentation fault, bus error, illegal instruction, ..., things that happen when your app for example tries to access an invalid pointer address.

You can also install handlers for those:

#include <signal.h>

void signalHandler(int signal)
{
}

    // Somewhere in your start-up code.
    signal(SIGSEGV, signalHandler);
meaning-matters
  • 21,929
  • 10
  • 82
  • 142
  • thanks! Could you tell me where could I find the documentation for this? – AppsDev May 24 '13 at 06:19
  • 1
    Type `man signal` in a MacOS X Terminal. Well [here](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/signal.3.html) it is. – meaning-matters May 24 '13 at 09:11
  • Thanks. For signals such as, for example, SIGSEGV (I think that corresponds to EXEC_BAD_ACCESS), or SIGILL... is it possible to get more info about the crash? file and line or something? – AppsDev May 30 '13 at 15:29