Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS app: Is there a life after crash and termination? [duplicate]

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?

like image 804
mafonya Avatar asked Dec 26 '22 18:12

mafonya


2 Answers

Doing any non async-safe task when the app crashed is highly NOT-recommendable!

  1. You are not allowed to allocate any new memory at that time
  2. You are only allowed to use async safe code (Any Objective-C code is NOT async safe)
  3. You need to take into account that memory is already corrupted
  4. You need to implement async-safe networking code
  5. and many many more reasons.

See these blog posts from Landon Fuller, the author of PLCrashReporter:

  1. http://landonf.bikemonkey.org/code/crashreporting/Reliable_Crash_Reporting_1.1.20130119.html
  2. http://landonf.bikemonkey.org/code/objc/Reliable_Crash_Reporting.20110912.html

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.

like image 97
Kerni Avatar answered Dec 28 '22 09:12

Kerni


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 ;-)

like image 22
Andrea Avatar answered Dec 28 '22 10:12

Andrea