user945620
user945620

Reputation:

iOS: Does exit(0) generate a crash report and if so what is the alternative?

I heard that merely using exit() and even providing a zero parameter will result in iOS generating a crash report. But in some cases it is better to perform an exit(0). So, what is the accepted way to exit an app if exit() is not allowed? Thanks.

Upvotes: 1

Views: 1723

Answers (4)

Jim
Jim

Reputation: 73936

There is no accepted way for an application to quit itself. From the iOS Human Interface 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.

Upvotes: 1

hotpaw2
hotpaw2

Reputation: 70703

If you want your app to no longer be in the foreground, have it send a valid URL to Safari. If you don't want your app to be in the background when Safari comes to the foreground, set the UIApplicationExitsOnSuspend key in your app's plist. If "somehow" an app integrity check fails (bad checksum of receipt validation code, etc.), then maybe trash some memory pools and/or your own call stack and let the OS deal with it.

Upvotes: 0

Michael Dautermann
Michael Dautermann

Reputation: 89509

A) do not call exit as part of normal application flow. That will get your app rejected from the app store for certain.

and B) if you want a backtrace and or crash report, throw an exception and the resulting crash log will show where the exception happened (with a backtrace).

I sense that your question is simply about quitting your app though. You're not supposed to quit the app programatically but instead let the user quit when s/he decides it's time to kill the app. In any event, when your app is finished up doing whatever it is that it's doing, one nice thing you can do is release all the resources you can as your app goes into the background state. Here's a related question that might help you out.

Upvotes: 1

pmk
pmk

Reputation: 1897

Why would you want to quit / crash your app programmatically? If you tell us more about what you are trying to do people could think of a work around

Upvotes: 0

Related Questions