How can I close an iPad app in Objective-C? - iphone

I would like to close an iPad application as a result of clicking on a UIButton. However, I have not seen how to do this in the Apple documentation.
What call needs to be made to close an app?
Thanks.

You can call exit(0) to terminate the app. But Apple don't like this as this gives the user a feeling of sudden crash. If you still want to have an exit function (with a potential risk of rejection) then you should also send your app delegate the applicationWillTerminate message (if you have anything important there) before performing the exit.

It says:
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.

The only way for a user to exit an application is by pressing the Home button. You can't do it in your app, at least not in a way that Apple would accept.

You can try to use command:
exit(0);

Related

Can I Use the Exit(0) function on IOS when i have no Internet Connection and pass Appstore Test

My App relay heavily on server data, when i have no connection to my server i cant present any data. so i present to the user a screen explaining him the no connection situation and give him a button to exit the application
my question is: will it pass Appstore tests? i never tried it before and i know they dont like apps to use exit(0), i was also was suggested to put a screen with no buttons and block the user from going back to other app screens and put a message on this screen and make the user to click on the home button in order not to use exit(0)
is that allowed?
No, you must not call exit. Your app will 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.
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.
http://developer.apple.com/library/ios/#qa/qa1561/_index.html

Is it possible to quit iOS app after we do some checks

We don't want the user enter our app if the app is out-dated.
Is that is possible to quit a iOS app when we do some date check BEFORE the app launch?
Or it is possible to quit the application after the main view is loaded?
Before the app launches: no. The launch animation is already in progress when the OS calls main.
After some time (1-2 sec): yes. You can use one of
[[UIApplication sharedApplication] terminateWithSuccess];
exit(0);
abort();
assert(0);
pthread_kill(pthread_self());
so many ways, but neither will go through AppStpre - you're not supposed to close your app programmatically. You're supposed to notify the user via an UIAlertView about the outdated app and disable interaction with the app.
According to Apple you cannot exit(quit) your application through code. i.e if you use exit(0). Your application will be rejected for that. Although you can use exit(1) and delay the exit time of your application. Or you may like to use local notification which is quite handy.
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

Call applicationDidEnterBackground manually

I want to send my Application to background simply clicking on Button inside my Application.
Is there any way to call applicationdidenterbackground manually or any other way ?
iOS Human Interface Guidelines says "Don't Quit Programmatically", whereby quitting must be understood as including "suspending":
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.
If you really want to exit your app programmatically, then you can call exit(0);, but I doubt that you app will pass the Apple review.
Unfortunately There is no any officialy way to force app to background state(Pause state).

How do i terminate an iPhone application gracefully in code

What is the proper way of ending an application on the iPhone when you are finished with it?
thanks,
anton
Jaanus is referring to this paragraph in the Apple iPhone Human Interface Guidelines
Stopping
People quit an iPhone application by opening a different application. In particular, note that people don’t tap an application close button or choose Quit from a menu. In iOS 4.0 and later, and on certain devices, the quitting application moves to a suspended state in the background. All iPhone applications should:
Be prepared to quit at any time. Therefore, save user data as soon as possible and as often as reasonable.
Save the current state when stopping, at the finest level of detail possible. For example, if your application displays scrolling data, save the current scroll position.
iPhone applications should never quit programmatically because doing so looks like a crash to the user. There may be times, however, when external circumstances prevent your application from functioning as intended. The best way to handle this is to display an attractive screen that describes the problem and suggests how users can correct it. This helps users in two ways:
It 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 certain circumstances prevent only some of your application's features from working, you can display either a screen or an alert when users activate the feature. Although an alert doesn't allow much flexibility in design, it can be a good choice if you can:
Describe the situation very succinctly
Supply a button that performs a corrective action
Display the alert only when users try to access the feature that isn’t functioning
As with all alerts, the less users see them, the more effective they are. For more information about creating alerts, see “Using Alerts.”
There is no way for an iPhone application to quit/terminate itself. Apple actively advises against it in their Human Interface and/or programming guides (can't remember which exactly) because it would look like a crash to the user.
An app should not terminate by itself.
Also, avoid showing an "exit screen" that prompts the user to quit the app manually as in iOS4, the app might stay open in the background and your user would be stuck in that exit state.

Remotely Closing the App

I have a button in my UI and was wondering if you are able to close the app and exit to the homescreen if you press it. Thanks!
You can always call exit(0) but it is against Apple's design guidelines to close applications programatically. The recommended way is when the user press the home button.
I don't know your thoughts for doing this, but
try explaining why or at least think it over again :)
A snippet from the HIG
iPhone applications should never quit
programmatically because doing so
looks like a crash to the user. There
may be times, however, when external
circumstances prevent your application
from functioning as intended. The best
way to handle this is to display an
attractive screen that describes the
problem and suggests how users can
correct it. This helps users in two
ways: ■ It 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
This method works also [[UIApplication sharedApplication] terminateWithSuccess];, but as mentioned shouldn't be used for distribution on the AppStore.