I have a tab based app, which last tab button is "Exit" how can I quite iPhone App, on click of that last tab bar?
-
There is no way to do this if you are going to put your app on AppStore. – iOS Dev Jan 21 '14 at 13:45
-
@Euroboy may be I can load view controller on that click and make app exit on that view controller load? is there such a way? – Kam Jan 21 '14 at 13:46
4 Answers
I can't express how strongly I wouldn't recommend this - just DON'T
This will get your app rejected from the App Store in the Apple App Store Review Process.
If you insist on it though you could use exit(0);
If the user wishes to exit your app they have the Home button at the bottom of the device so there is no need to do this at all, it will create confusion and and look as if the app has crashed.
See this, it states.
There is no API provided for gracefully terminating an iOS application.
Warning: Do not call the exit function. Applications calling exit will appear to the user to have crashed, rather than performing a graceful termination and animating back to the Home screen.
So this means there is no Public API that will allow you to do this gracefully so your app would get rejected under
2.5 - Apps that use non-public APIs will be rejected
From source Apple Review Guidelines
Basic definition of exit()
exit
. The exit statement terminates your program with an exit code. Its prototype isvoid exit(int exitcode);
exit
is used by some operating systems and may be used by calling programs. By convention, anexit
code of0
means that the program finised normally, and any other value means that some error or unexpected results happened.
Also another source that says don't use it is here. That is basically all of the Apple Documentation saying under no circumstance should you be exiting the app programmatically.
-
I've used this in an app store app that was approved. Was a client requirement I also would NOT recommend doing this. – CW0007007 Jan 21 '14 at 13:48
-
@CW0007007 See links I have provided and quotes from those links and see Apple review guidelines. This was probably just one that slipped through, I have had an app slip through before and then rejected when I have done an update. `exit(0)` should not be used at all. – Popeye Jan 21 '14 at 13:53
-
yes, I'd avoid it and have done since, I think it was lucky. Was back in iOS 5 days, possibly even iOS 4. – CW0007007 Jan 21 '14 at 14:03
-
I think it has always been this way, but things do slip through the system. – Popeye Jan 21 '14 at 14:06
-
Yes, thinking back it was a medical app with terms and conditions, if the user didn't accept it would close the app. Not the correct way to do it by any means but clients... – CW0007007 Jan 21 '14 at 14:07
-
No offense to you or your client but that sounds horrible, but I have had clients request silly things as well. Not sure they fully understand it sometimes. Normally I will just turn around and tell them straight that for the apps own good this will not be happening. It's not just them that will get bad rep for it, as the developer (or development company) you will also get seen in a bad way. – Popeye Jan 21 '14 at 14:10
-
Preaching to the converted. At the time I had no say, recommended it wasn't a good way to do it. Oh well, their loss... Happy Coding :-) – CW0007007 Jan 21 '14 at 14:12
-
I had to laugh at most of the answers on this question. They follow the format of "Don't do this, but here's how!" (-‸ლ) – Jasarien Jan 21 '14 at 17:12
-
@Jasarien I was just giving them the option for if they want to ignore Apples recommendations and restrictions. As least they can make an informed decision then. – Popeye Jan 21 '14 at 18:21
We can not send app in background or we can not quit app because Quitting your application or sending it to the background programmatically is a violation of the iOS Human Interface Guidelines, because people tend to interpret this as a crash and apple never allows such apps.

- 1,788
- 2
- 23
- 41
You can exit an iOS Application with the following code
exit(0)
However,
From Apple's Human User Guidelines...
Don’t Quit Programmatically
Never quit an iOS application programmatically because people tend to interpret this as a crash. However, if external circumstances prevent your application from functioning as intended, you need to tell your users about the situation and explain what they can do about it. Depending on how severe the application malfunction is, you have two choices.
Display an attractive screen that describes the problem and suggests a correction. A screen provides feedback that reassures users that there’s nothing wrong with your application. It puts users in control, letting them decide whether they want to take corrective action and continue using your application or press the Home button and open a different application
If only some of your application's features are not working, display either a screen or an alert when people activate the feature. Display the alert only when people try to access the feature that isn’t functioning.

- 3,074
- 4
- 22
- 33
!!! PLEASE DONT DO IT !!! an iphone app should not be terminated by user! Your app will be rejected!
check UITabBarDelegate
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
if( item == exitItem ) {
exit(0);
}
}

- 2,807
- 19
- 26