user1898387
user1898387

Reputation: 101

iOS is exit(0) deprecated?

Does anyone know if exit(0) is deprecated in iOS application? I know it is not a good decision to manually terminate the app, but does Apple ban the application if we use it in the code?

Upvotes: 6

Views: 10277

Answers (3)

Mark McCorkle
Mark McCorkle

Reputation: 9414

No, you must not call exit as your app SHOULD be rejected. This has been repeatedly discouraged by Apple and is known to cause serious bugs with iOS multitask switching. You should simply leave the user to use the home button themselves.

http://developer.apple.com/library/ios/#qa/qa1561/_index.html

"Additionally, data may not be saved, because -applicationWillTerminate: and similar UIApplicationDelegate methods will not be invoked if you call exit. If DURING DEVELOPMENT or TESTING it is necessary to terminate your application, the abort function, or assert macro is recommended."

2012-04-09
Updated to more strongly discourage the exit function, and include best practices for debugging.

2008-08-27
New document that discusses best practices for terminating an iOS application in code.

Straight from the iOS Human Interface Guidelines http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/UEBestPractices/UEBestPractices.html#//apple_ref/doc/uid/TP40006556-CH20-SW27

"Don’t Quit Programmatically

Never quit an iOS app programmatically because people tend to interpret this as a crash. However, if external circumstances prevent your app 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 app 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 app. It puts users in control, letting them decide whether they want to take corrective action and continue using your app or press the Home button and open a different app

If only some of your app's features are unavailable, display either a screen or an alert when people use the feature. Display the alert only when people try to access the feature that isn’t functioning.

If Necessary, Display a License Agreement or Disclaimer

If you provide an end-user license agreement (or EULA) with your iOS app, the App Store displays it so that people can read it before they get your app.

If possible, avoid requiring users to indicate their agreement to your EULA when they first start your app. Without an agreement displayed, users can enjoy your app without delay. However, even though this is the preferred user experience, it might not be feasible in all cases. If you must display a license agreement within your app, do so in a way that harmonizes with your user interface and causes the least inconvenience to users.

If possible, provide a disclaimer within your app description or EULA. Users can then view the disclaimer in the App Store, and you can balance business requirements with user experience needs."

Upvotes: 5

Jason Whitehorn
Jason Whitehorn

Reputation: 13685

No, Apple will not reject your app for using exit(0).

You are correct, it is not a great design choice, but it can be useful sometimes.

As Larme mentioned, if used incorrectly, it can be perceived as a crash and a crash will result in your app being rejected.

However, it can be very useful in applicationDidEnterBackground when (on a conditional basis ) you might want to force the app to start a fresh.

Upvotes: 6

Larme
Larme

Reputation: 26036

I got an app which was rejected because of a way of exit (via UIAlertView), doing an exit(5) when user click on the correct button.

I received that:

We found that your app includes a UI control for quitting the app. This is not in compliance with the iOS Human Interface Guidelines, as required by the App Store Review Guidelines.

Please refer to the attached screenshot/s for reference.

The iOS Human Interface Guidelines specify,

"Always Be Prepared to Stop iOS applications stop when people press the Home button to open a different application or use a device feature, such as the phone. In particular, people don’t tap an application close button or select Quit from a menu. To provide a good stopping experience, an iOS application should:

  • Save user data as soon as possible and as often as reasonable because an exit or terminate notification can arrive at any time.

  • Save the current state when stopping, at the finest level of detail possible so that people don’t lose their context when they start the application again. For example, if your app displays scrolling data, save the current scroll position."

It would be appropriate to remove any mechanisms for quitting your app.

A "hidden" exit could be understood as a crash for the user, no?

Upvotes: 6

Related Questions