views:

1317

answers:

3

I have just discovered the nifty unhandled exception handler for cocoa-touch. Now that i can gracefully notify the user about any unhandled exceptions that might crash my application. I'd like to shut down my application after notifying the user that a crash has occured. Does anyone know how to shut down an application programmatically?

+6  A: 

You can call [[UIApplication sharedApplication] terminate]; - that won't build the screenshot Springboard uses to animate the application's exit, though, so the screen will just go black until the icons move in. There doesn't seem to be a published way to do this; the UIApplication header doesn't even mention the -terminate method, so you may just not be meant to do it at all.

Noah Witherspoon
I think you mean [[NSApplication sharedApplication] terminate], rather than UIApplication.
Pete Hodgson
No. Note tags: "iphone" and "cocoa-touch".
Noah Witherspoon
*** -[UIApplication terminate]: unrecognized selector sent to instance 0x1214900... using `exit(0);` works perfectly, though.
znq
My app was just rejected because of `exit(0);`. It looks like a crash. I use to inform the user when there is no internet connection and once he closes the alert I close the app by using `exit(0);`. Appears that Apple doesn't like it...
Michael Kessler
A: 

Apple's documentation says there is no "normal" way to shut down. In your case - an unhandled exception - immediate termination makes sense anyway.

Chris Lundie
+3  A: 
exit(0);

will do the trick...

Rich
My app was just rejected because of `exit(0);`. It looks like a crash. I use to inform the user when there is no internet connection and once he closes the alert I close the app by using `exit(0);`. Appears that Apple doesn't like it...
Michael Kessler