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
2008-10-28 03:48:05
I think you mean [[NSApplication sharedApplication] terminate], rather than UIApplication.
Pete Hodgson
2010-05-05 23:41:46
No. Note tags: "iphone" and "cocoa-touch".
Noah Witherspoon
2010-05-06 16:42:33
*** -[UIApplication terminate]: unrecognized selector sent to instance 0x1214900... using `exit(0);` works perfectly, though.
znq
2010-06-02 14:02:18
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
2010-09-28 04:10:24
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
2008-10-28 05:51:32
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
2010-09-28 04:10:04