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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:40:58+00:00 2026-05-23T14:40:58+00:00

I am working on an application and i have to check internet connectivity. I

  • 0

I am working on an application and i have to check internet connectivity. I am using two files Reachability.h and Reachability.m. Now i have to show an alert when internet is not working.

But when my observer check the internet it shows alert view more then one time. and some times it shows the alert more 9-10 times.
my code is here:

in .h file

Reachability* internetReachable;
    Reachability* hostReachable;
    NetworkStatus internetStatus;

in .m file

        internetReachable = [[Reachability reachabilityForInternetConnection] retain];
        [internetReachable startNotifier];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
        hostReachable = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
        [hostReachable startNotifier];



- (void) checkNetworkStatus:(NSNotification *)notice    
     {
        internetStatus = [internetReachable currentReachabilityStatus];

        if (internetStatus != NotReachable){
            NSLog(@"internet is on");

        }
        else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"Server not connected or down!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
            [alert release];
            internetCount++;
        }           
}

this code is in delegate and similarly i am using this code in other classes where ever i have to check internet

plz help

  • 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-23T14:40:59+00:00Added an answer on May 23, 2026 at 2:40 pm

    I don’t use Reachability because I’ve had problems like you, so I created my own implementation. Just import the header file below and then call [self networkIsReachable] to check for an internet connection.

        #import <netinet/in.h>
        - (BOOL)networkIsReachable 
        {
            struct sockaddr_in zeroAddress;
            bzero(&zeroAddress, sizeof(zeroAddress));
            zeroAddress.sin_len = sizeof(zeroAddress);
            zeroAddress.sin_family = AF_INET;
    
            SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
            SCNetworkReachabilityFlags flags;
            BOOL gotFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
            CFRelease(defaultRouteReachability);
            if (!gotFlags) {
                return NO;
            }
            BOOL isReachable = flags & kSCNetworkReachabilityFlagsReachable;
    
            BOOL noConnectionRequired = !(flags & kSCNetworkReachabilityFlagsConnectionRequired);
            if ((flags & kSCNetworkReachabilityFlagsIsWWAN)) {
                noConnectionRequired = YES;
            }
    
            return (isReachable && noConnectionRequired) ? YES : NO;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an working application. Now I want to change the table names of
I have a working application using python and zeromq and I would like to
I have checked using instruments and not found any memory leaks. when i check
I'm working on Android application which is taking content from internet using JSON, I
I have a working web application that uses username/password SpringSecurity configuration. Now I want
I have my shell application working and I now want to ensure that a
I am working on a WinForms application and have to show the Application Icon(Notification
I have application which is working best with Wifi,3G.. Now what i want is
I'm working on Android application which have two different tabhost : Main and Child.
I'm working on an application that downloads some data from the internet using NSData's

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.