Close app when internet is not available

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?


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.


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.

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.

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]

Need Your Help

RODBC sqlSave() and mapping column names

r rodbc

I've a question about using sqlSave. How does R map RODBC data in the data frame to the database table columns?