2

I am writing codes for a project where i can not use several crash reporting tools due to some privacy issue. So i am searching to manage a send email having crash report if crash occurs without the involvement of third party reporting tool.

Anupam Gupta
  • 623
  • 1
  • 7
  • 18

2 Answers2

2

In your application delegate declare API like:

void uncaughtExceptionHandler(NSException * exception)
{
    // Here you can:
    // 1. Set some boolean in user defaults that app crashed.
    // 2. Dump this data (below) in some file in documents directory.

    NSLog(@"Uncaught Exception: %@", exception.reason);
    NSLog(@"CrashSymbols: %@", exception.callStackSymbols);
}

Then set in "application:didFinishLaunchingWithOptions:":

NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);

Then when your application next launches, if boolean (1) is set in user defaults, read this data (2) and email.

gagarwal
  • 4,224
  • 2
  • 20
  • 27
  • 1
    Uncaught exceptions are not the only cause of crashes; this will miss lots of possible errors. – Jesse Rusak Mar 16 '15 at 20:42
  • can i sent to real time? means whenever any crashes occurs app ask us to email the crash report.? – Anupam Gupta Mar 16 '15 at 20:46
  • There is this nice article which explains this in detail: http://www.cocoawithlove.com/2010/05/handling-unhandled-exceptions-and.html – gagarwal Mar 16 '15 at 20:54
  • 1
    You should *not* do this on iOS. Whenever a crash or exception occurs, your app is in an unsafe state and calling any other non async safe code (including Objective-C code) can lock up the device or damage user data. That linked article is 5 (!!) years old and isn't a safe approach on crash reporting! As a reference read http://landonf.bikemonkey.org/code/objc/Reliable_Crash_Reporting.20110912.html and http://stackoverflow.com/questions/3378696/iphone-try-end-try/3379240#3379240 – Kerni Mar 16 '15 at 23:16
1

You can use PLCrashReporter framework in your iOS application, whenever the application is started, it should search for saved crash logs then send email using MFMailViewComposer.

https://www.plcrashreporter.org/

Duyen-Hoa
  • 15,384
  • 5
  • 35
  • 44
  • 1. PLCrashReporter doesn't search for crash logs, it catches them and writes a report by itself. 2. If you don't want to use an existing crash reporting framework, you won't be able to catch crash log data safely and accurately. Whatever you will do yourself, even though something might work in your quick test, will be wrong. – Kerni Mar 16 '15 at 23:13
  • Yes, indeed, it created the crash logs whenever application crashes. Then, there also APIs to retrieve those crashes (be called when application is started as per my answer). – Duyen-Hoa Mar 16 '15 at 23:41