5

I need to close the application whenever user taps on the button(i need to keep IBAction for closing the app).Like in games menu we have exit button when we tap on it we come out from the game.Same thing i need.How can i do this .Thanks in advance

Hemang
  • 26,840
  • 19
  • 119
  • 186
iphoneStruggler
  • 123
  • 2
  • 3
  • 10
  • I've not heard of any game that has an exit button to quit the application altogether. Most games allow the player to quit to the main menu, but not to the home screen... – BoltClock Oct 26 '10 at 06:13
  • For those searching for this answer, that can use Private APIs, [see this answer](http://stackoverflow.com/a/15997772/119114). – Nate Apr 14 '13 at 10:05

7 Answers7

14

Please see: How do I programmatically quit my iPhone application?

WARNING: It is possible to quit the application by calling exit. Applications calling exit will appear to the user to have crashed, rather than performing a graceful termination and animating back to the Home screen. Such usage provides a negative experience and is strongly discouraged.

fabian
  • 111
  • 1
  • 10
Chris Gummer
  • 4,772
  • 1
  • 24
  • 17
6

Instead of it, If you want your app to terminate when the user presses the home button, set the value of UIApplicationExitsOnSuspend to YES in your app's Info.plist file. If you do this, when the user taps the home button the applicationWillTerminate: method of your app delegate will be called and then your application will terminate.

Amal T S
  • 3,327
  • 2
  • 24
  • 57
Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188
3

exit(0); will terminate your application, but as i know we can not call exit(0); or terminate in an iPhone application. Instead we can put an alerview without button, "saying please quit the application".

YPK
  • 1,851
  • 18
  • 18
1

This is the best way to do this

UIApplication *myapp = [UIApplication sharedApplication];
[myapp performSelector:@selector(suspend)];

Include this code where ever you need thats it. But still not recommended by apple Developer apple link

Nagarjun
  • 6,557
  • 5
  • 33
  • 51
0

There's one non-recommended way that crashes the app:

[[UIApplication sharedApplication] sendAction:SIGKILL to:[UIApplication sharedApplication] from:self forEvent:nil];

The app will not close the proper way or save. It's more recommended to use a UIAlertView with no buttons to force the user to close the app.

Halvor Holsten Strand
  • 19,829
  • 17
  • 83
  • 99
JomanJi
  • 1,407
  • 1
  • 17
  • 27
0

There is no API provided for gracefully terminating an iPhone application. Under the iPhone OS, the user presses the Home button to close applications. see link text

Gyani
  • 2,241
  • 1
  • 24
  • 38
0

exit(0) is not apple standard way to exit the app and apple highly discourages it.Though, sometimes it approves some application.Give proper UI to show if any functioning is not working or give suggestions regarding it to user.killing app programmatically is not right way.Let user Handle the exit on their own.

K.K
  • 79
  • 2
  • 8