tags:

views:

22

answers:

2

Hello,

I have a view in my app which says something like "sorry for the crash, please restart the app", and I'd like to show it after crash. so is there any general way I can detect a crash that is about to happen and show the view before it does?

Thank you.

+1  A: 

I doubt it. A crash is a crash. The best you could do is wrap @try/catch around your code in main.m, but I wouldn't recommend it and it wouldn't catch serious errors. iPhone users recognize crashes when the apps go away. I'm willing to bet that showing a special view for a crash would be even more annoying to users, as if you so expect a crash you even made a screen! ;-) Users will grow to hate that screen.

What is recommend is to capture the crash and then the next time the user runs the app, you can say "We see your app has crashed" and perhaps send a dump of the stack trace to yourself so you can see what happened. You can handle the crashes by defining this method in your app delegate:

void uncaughtExceptionHandler(NSException *exception) {
    // save exception to file
}

And call this method in your didFinishLaunching method:

NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);

Next time they start the app, check for that file and if it exists, send it.

ZaBlanc
+1  A: 

Can recommend this Cocoa With Love blog post. It has a sample project you can learn from too.

petert