Re: Exit an Application
Re: Exit an Application
- Subject: Re: Exit an Application
- From: WT <email@hidden>
- Date: Tue, 14 Apr 2009 02:07:20 +0200
On Apr 13, 2009, at 11:52 PM, Uli Kusterer wrote:
Well,
calling exit() is the best way to shoot yourself in the foot. That
would exit the app immediately, without saving any unsaved
documents, without writing any cached NSUserDefaults changes to the
hard disk etc. Its effect in a regular Cocoa application is only
slightly better than choosing "Force Quit" and shooting down the
app. In short, don't do it.
[[NSApplication sharedApplication] terminate: nil];
or the slightly shorter and a thoretically a tad more dangerous
similar call with NSApp in it are really the only option. (Well,
theoretically you could send yourself a "quit" Apple Event, but
that's only of academical interest...)
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
And for anyone curious about the same question in relation to the
iPhone OS, two comments come to mind:
a) you're not supposed to quit your own application; the user is in
charge and can hit the home button if he/she wants to quit your
application
b) still, if you really want to programmatically quit your
application, you can try the analogous
[[UIApplication sharedApplication] performSelector:
@selector(terminate)];
It works, but the final animation that an application goes through
when the application quits to the home screen (the zooming effect)
does not happen, which might confuse the user into thinking that your
application crashed.
Wagner
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden