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 8566915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:45:54+00:00 2026-06-11T17:45:54+00:00

Here i have a very interesting topic for discussion or you can say i

  • 0

Here i have a very interesting topic for discussion or you can say i need a suggestion for the better approach.

Here is my code

+ (BOOL) isConnected
{
     BOOL flag = TRUE;
     if (![self isHostReachable])
     {
           flag = FALSE;
           NSString* alertTitle= @"";
           NSString* alertMessage= @"";

           if (![self isInternetReachable])
           {
                 alertTitle = @"Network unavailable";
                 alertMessage = @"We can't connect to the Internet. Check your            settings/connection.";
           }
           else
           {
                 alertTitle = @"Server not responding";
                 alertMessage = @"Server not responding at the moment. Please try again later. Sorry for inconvenience";
           }
           UIAlertView *alert=[[UIAlertView alloc] initWithTitle:alertTitle
                                                  message:alertMessage
                                                 delegate:self
                                        cancelButtonTitle:@"Close"
                                        otherButtonTitles:nil];

           [alert show];
     }
     return flag;
}

+ (BOOL) isInternetReachable
{
     Reachability *netReachability = [Reachability reachabilityForInternetConnection];
     NetworkStatus netSat = [netReachability currentReachabilityStatus];
     return (!(netSat == NotReachable));
}

+ (BOOL) isHostReachable
{
     Reachability *hostReachability = [Reachability reachabilityWithHostname:   [Connection returnHostName]];
     NetworkStatus netSat = [hostReachability currentReachabilityStatus];
     return (!(netSat == NotReachable));
}

In my code, I used to call the “isConnected” method in order to check the connectivity status, before asking my server for data.

In the method, I am checking the hostReachability first of all. My thinking behind doing this is to save the computation time.

  • If the hostReachability returns true it implies netConnectivity is also there(no need to verify). So here we are done with just one computation.
  • If the hostReachability returns false, then I am checking is it the net connectivity thats responsible for it. Hence two computations.

But it usually seen that the code first verifies the netConnectivity, if its ok, then verify the hostReachability.

So most of the times Two computations, thats in contrast with my way of getting the thing done.

Please suggest which one you think is better approach?

  • 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-06-11T17:45:55+00:00Added an answer on June 11, 2026 at 5:45 pm

    Well netConnectivity would verify if the network is in position and not down due to any of the 100 reasons, then the host is verified to be reachable as the server may be down due to some issue.

    If the network is verified as failed connection it will rule out verifying the host in the first place. vice-versa is not true though..
    I hope that was useful as explanation to you.
    Cheers!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a very complex Oracle package here (over 4,100 lines of code) that's
Here is one very interesting problem. I am using SQL Server 2008. I have
I ran across some very interesting code that makes me wonder about what bool
Have a very interesting situation and can't seem to find anything concrete on the
I have a very interesting challenge here for my Flex project development. I now
I have a very interesting task that I need help with. The description is
I have a very strange behavior with Request.Form . Here are two IIS 7
I'm learning assembly and I have a very basic loop here segment .data msg:
Well, I think I have a very basic doubt here: I'm developing an app
i'm missing something fundamental here. i have a very simple custom class that draws

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.