Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 324343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:06:55+00:00 2026-05-12T09:06:55+00:00

I would like to check reachability before/when a webView is shown in my app.

  • 0

I would like to check “reachability” before/when a webView is shown in my app.

So far I’ve included the reachbility.h/.m files as well as added the SystemConfiguration.framework to the project.

And that’s about where the agreements I have found on the internet end, from all of the posts and blogs etc. etc. everyone has a different idea/opinion of what to do after that. Additionally, I have found a lot partial code snippets that aren’t really a complete solution, on which reachibility methods to call etc. etc. how to use them etc.

I have also found that some warn that you should try to reconnect before checking reachability…but I haven’t found a consensus or a full solution. My app seems to reconnect to wifi without any extra code… so I’m a litte confused here too…

Any help to clear the muddy waters would be appreciated. I’m just looking for a simple straightforward solution.

Answer Accepted: I would like to note to newbies who may read this q/a later… that you will want to do the following:

Add this into your .h file:

- (BOOL) connectedToNetwork: (NSString *) remoteServer;
- (void) appLoadError: (NSString *) altertTitle alertMessage: (NSString *) altertMsg;

And you will need to import these at the top of your .m file:

sys/socket.h

netinet/in.h

netinet6/in6.h

arpa/inet.h

ifaddrs.h

netdb.h

SystemConfiguration/SystemConfiguration.h

Correct me if it is wrong… It seems to work fine for me…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:06:55+00:00Added an answer on May 12, 2026 at 9:06 am

    I have always used this method in my App Delegate when I need to require Internet access. I have tuned it for different access types over time and it has served me well. It is a variant of one of the many methods you can find after a quick Google search on this topic.

    It is a tricky thing to come up with a hard and fast strategy around this. The platform itself offers different connectivity options that have pros and cons based on the needs of each specific application. The method I use below is just a general connectivity test meaning the device can reach the Internet via some connectivity mechanism.

    - (BOOL) connectedToNetwork: (NSString *) remoteServer {
        // Create zero addy
        struct sockaddr_in zeroAddress;
        bzero(&zeroAddress, sizeof(zeroAddress));
        zeroAddress.sin_len = sizeof(zeroAddress);
        zeroAddress.sin_family = AF_INET;
    
        // Recover reachability flags
        SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
        SCNetworkReachabilityFlags flags;
    
        BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
        CFRelease(defaultRouteReachability);
    
        if (!didRetrieveFlags){
            NSLog(@"Error. Could not recover network reachability flags");
            return NO;
        }
    
        BOOL isReachable = flags & kSCNetworkFlagsReachable;
        BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
        BOOL nonWiFi = flags & kSCNetworkReachabilityFlagsTransientConnection;
    
        NSURL *testURL = [NSURL URLWithString: remoteServer];
        NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL  cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0];
        NSURLConnection *testConnection = [[NSURLConnection alloc] initWithRequest:testRequest delegate:self];
    
        return ((isReachable && !needsConnection) || nonWiFi) ? (testConnection ? YES : NO) : NO;
    }
    

    I usually call this inside applicationDidFinishLaunching. If the check returns false, I usually generate an error message (see below). This is because Apple forbids exiting the application by any means other than the home button on the device.

    ...
    else if(![self connectedToNetwork: [NSString stringWithFormat: @"http://%@:%@/", sharedSettings.server, sharedSettings.port]]){
            [self appLoadError: @"No Internet Detected" alertMessage:@"This application requires an active Internet connection.  No content is available."];        
    }
    ...
    - (void) appLoadError: (NSString *) altertTitle alertMessage: (NSString *) altertMsg {
        UIAlertView *loadErr = [[UIAlertView alloc] initWithTitle: altertTitle message: altertMsg delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
        [loadErr show];
        [loadErr release];
    
        // Load static screen
        UIImage *image = [UIImage imageNamed:@"Error_NoInternet.png"];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    
        [controller setNavigationBarHidden: YES animated: NO];
    
        [window addSubview: imageView];
        [imageView release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a table products and I would like to check if this
I would like to know whether there is a jQuery function which can check
I would like to update an open-source war file in Maven with some additional
I would like to massively use inline in my project to speed up performance.
I would like to have a counter, that counts backwards, and is stopped if
I'm having some trouble with Instruments. My app is working perfectly without crashes, but
I am using the Silverlight Toolkit for Windows Phone 7 ( http://silverlight.codeplex.com/ ). What
using CodeIgniter normally one has to specify the controllers in the config/routes.php file. This
when i try to attach entity to context i get an exception An object
Lets say I have a String: Go to this page: http://mysite.com/?page=1 , and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.