4

I want to exit my application programatically, I googled, some people suggesting to use exit(1), but apple is not supporting that I guess. If it is the case, How do I exit my application programatically. Any helps appreciated.

James Webster
  • 31,873
  • 11
  • 70
  • 114
Newbee
  • 3,231
  • 7
  • 42
  • 74
  • 3
    if you plan to publish the app to app store. please dont do that. people will think your app crashs, apple doesnt allow it. – janusfidel Aug 30 '12 at 10:51
  • There is no way to do this in iOS SDK. – msk Aug 30 '12 at 10:51
  • 3
    According to apple you can't exit your application programitically. My recent application got rejected by apple for this reason. Check [this](http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/UEBestPractices/UEBestPractices.html#//apple_ref/doc/uid/TP40006556-CH20-SW27) – Nitish Aug 30 '12 at 10:53
  • If you do that you'll never enter the app store, let alone some user exiting your app. – Bourne Aug 30 '12 at 10:54
  • Any Idea how do I implement an option signout and exit(its a button). I have seen Skype is exiting the application, are they really exiting? – Newbee Aug 30 '12 at 10:54
  • 1
    Unfortunately you have to live without exiting your application. – Nitish Aug 30 '12 at 10:55
  • Is there any way to go to main page(Dash) from our application programtically? So that I can use as exit? – Newbee Aug 30 '12 at 10:57
  • u can give alert like Quitting application and then after 2 sec exit(1). Then apple might approve application – Paresh Navadiya Aug 30 '12 at 11:03
  • look at here. http://stackoverflow.com/questions/7254666/how-do-i-exit-my-ios-app-gracefully-after-handling-a-local-notification and here http://stackoverflow.com/questions/3097244/exit-application-in-ios-4-0 there are fare discussion over here. – rptwsthi Aug 30 '12 at 11:06
  • @Nitish Skype is doing the same. – Newbee Aug 30 '12 at 11:07
  • There is sighout option in skype, but it does not exit application. – Nitish Aug 30 '12 at 11:10
  • @Nitis They are providing a check box to exit also. – Newbee Aug 30 '12 at 11:14
  • @user1587011 : Please help me to find this option. Not able to see it. – Nitish Aug 30 '12 at 11:19
  • @Nitish Sorry man it was my mistake, I have seen in Android device. You are right. – Newbee Aug 30 '12 at 11:26

4 Answers4

15

exit(0); will work but don't use it

You shouldn't force close an app as the standard way to terminate an application is to press the home button (or use the multitasking bar)

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.

Source

James Webster
  • 31,873
  • 11
  • 70
  • 114
2

I believe u are not reading the comment properly thus posting the answer for ur question here: "Simply Don't do that. as apple does not allow application to crash like that."

look at here. How do I exit my iOS app gracefully after handling a Local Notification and here Exit application in iOS 4.0 there are fare discussion over here.

Community
  • 1
  • 1
rptwsthi
  • 10,094
  • 10
  • 68
  • 109
2

After the release of iOS4, multitasking(new feature) was added by APPLE. This feature enabled the users to keep the app into suspended state in the background if in between he has to do some other activity(e.g. picking up phone call). So Apple considers your app should be maintained in the background until the user deletes the application from the background. And after this if you want to exit use exit(0);, using this would further lead to rejection from AppStore

Vimal Venugopalan
  • 4,091
  • 3
  • 16
  • 25
-3

Here's a wrong way to accomplished exit function in your app. This is coming to mind when I read your question, never applied anywhere, so be careful if you'll gonna implement this!

- (void) exitApp
{
      NSArray *array = [[[NSArray alloc] init] autorelease];
      NSLog(@"%@",[array objectAtIndex:10]); //will crash here, looks like exit.
}

P.S. You can put this code inside your UIAlertView asking exit confirmation like Do you really want to exit?. In YES button pressed you can call [self exitApp]; User think that he'll exit from the app.

Hemang
  • 26,840
  • 19
  • 119
  • 186