Take the 2-minute tour ×

I want to close my app when an Internet Connection is not available.

I check that ,but how can I create an alert, and then close my app?


share|improve this question
that sounds unusual behaviour if you are considering a phone to be an occasionally connected device. –  Mitch Wheat Nov 4 '11 at 0:14
I've noticed apps that manage to do this (Words With Friends, for one). I don't like it, personally. –  Michael Petrotta Nov 4 '11 at 0:16
my app works with data from an web server, if there is no contection it didn't work, that's why i wanted this behavior. –  DaSilva Nov 4 '11 at 0:18

4 Answers 4

up vote 18 down vote accepted

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.


share|improve this answer
This is true. If your application cannot work without an active connection, you should display some static UI that explains that to the user. –  tjarratt Nov 4 '11 at 0:17

According to August's ans here

"On the iPhone there is no concept of quitting an app. The only action that should cause an app to quit is touching the Home button on the phone, and that's not something developers have access to.

According to Apple, your app should not terminate on its own. Since the user did not hit the Home button, any return to the Home screen gives the user the impression that your app crashed. This is confusing, non-standard behavior and should be avoided."

But if you still want to quit your app programmatically then there are two commands to quit the app.


2.[[NSThread mainThread] exit]
share|improve this answer

Your app should never close itself. iOS does not have the concept of quitting an app. You can inform the user that there is no internet connectivity and present a waiting screen or something else that shows them that your app is useless until the internet connection is available, but your app should continue running until the OS decides to shut you down.

share|improve this answer

Instead of closing it, consider explaining the situation to the user by the means of a popup.

First of all, download Reachability from Apple.

Add the classes Reachability.h,.m,delegates to your project. Then in your .m class import Reachability

#import "Reachability.h"

And in viewWillAppear or when you should display the alert:

//Connection check
    Reachability *reach = [Reachability reachabilityForInternetConnection]; 
    NetworkStatus netStatus = [reach currentReachabilityStatus];    
    if (netStatus == NotReachable)
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"Explain the situation to the user" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
        [alert show];
        [alert release];       

    else {
    //other actions.

As others said before me.

share|improve this answer

Your Answer


