Catch crash occurences and store to user defaults

Is there a way to catch the crashes from both swift and obj-c without using any 3rd party libraries? I want a way to note that my app has crashed, no stack trace needed just want some count of crashes stored to user defaults. I saw NSSetUncaughtExceptionHandler being used but it is only catching obj-c related errors. eg. force unwrapping nil is not caught here. I want a universal way of catching the crashes. also want to know if this can affect the crash reporting by 3rd party libraries

Is there a way to catch the crashes from both swift and obj-c … ?

Not in any way that DTS supports. See Implementing Your Own Crash Reporter for an in-depth explanation as to why we don’t help folks create their own crash reporter, and for some info on alternatives you can try, like MetricKit.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Is it possible to just identify that my app had crashed previously?

Not easily [1]. There are five ways that on iOS app’s process can stop:

  • It was terminated by the user (A).

  • It called exit (B).

  • It crashed (C).

  • It was terminated by the system for misbehaviour (D).

  • It was suspended in the background and subsequently terminated (E).

Case A case is relatively obscure. If your app is running and the user swipes up in the multitasking UI, the system will call your app’s -applicationWillTerminate:. That’s cool, and it means that you can track this case with some degree of reliability.

Case B shouldn’t happen, per QA1561, but if you do end up calling exit then that’s easy to track.

You can treat cases C and D the same because you can’t safely catch a crash within your app app (case C), per my comments up thread.

So that leaves you with trying to distinguish between cases C/D and E, and that’s really hard because there are so many situations where your app can execute in the background.

Which brings me back to another point from upthread, namely MetricKit. It gives you metrics on how your app has recently executed, using the MXAppExitMetric object. It also supplies you with crash reports via the MXCrashDiagnostic object. This isn’t exactly what you asked for, but you might be able to meet it in the middle.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] On iOS and its child platforms. It’s a different story on macOS.

Catch crash occurences and store to user defaults
 
 
Q