I am trying to create an iOS crash reporter tool. I wonder if the application can send crash info after it was terminated.
So my questions are: - What is a lifecycle of iOS application after termination? - Where can I read more about what iOS does to application on termination?
Doing any non async-safe task when the app crashed is highly NOT-recommendable!
See these blog posts from Landon Fuller, the author of PLCrashReporter:
You are trying to solve a problem, that is not a problem in the real world. People do restart their apps and will send the crash reports.
Yep, a sort of... you can handle exceptions, before iOS kills the crashing app, but you can't do any async operation (probably not totally true you can use background operation with expiration handler, or in iOS7 NSURLSession), such as sending the a file to a server, but you can do at the next restart.
The idea behind that is in -applicationDidFinishLaunching to set an exception handler:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSSetUncaughtExceptionHandler(&myExcHandler);
/* your code*/
}
myExcHandler is a C callback that accept an NSException
as parameters that it will be called when an exception occurs.
void myExcHandler(NSException *exception)
{
//set something on NSUserDefault to check at next start
}
It must be said that there are plenty of crashing report lib available. Do not reinvent the wheel ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With