• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: iPhone Testing Internet Connection?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iPhone Testing Internet Connection?


  • Subject: Re: iPhone Testing Internet Connection?
  • From: Jonathan del Strother <email@hidden>
  • Date: Tue, 15 Dec 2009 12:33:51 +0000

Perhaps you should be calling the internetConnection function, rather
than comparing its address to 0x0000001 ?

if (internetConnection() == YES)
....


2009/12/15 Chunk 1978 <email@hidden>:
> i have been researching how to do this, and while i believe my code is
> correct, i always receive the alert stating the internet connection is
> unavailable.  what am i doing wrong?
>
> -=-=-=-=-
> - (BOOL)internetConnection
>        {
>        //INTERNET CONNECTION TESTING
>        //Add the SystemConfiguration framework
>        //#import <SystemConfiguration/SCNetworkReachability.h>
>        //#include <netinet/in.h>
>
>        //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)
>                {
>                printf("Error. Could not recover network reachability flags\n");
>                return 0;
>                }
>
>        BOOL isReachable = flags & kSCNetworkFlagsReachable;
>        BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
>        return (isReachable && !needsConnection) ? YES : NO;
>        }
>
> - (IBAction)gotoAppStore
>        {
>        if (internetConnection == YES)
>                [[UIApplication sharedApplication] openURL:[NSURL
> URLWithString:@"http://www.google.com";]];
>                else
>                {
>                UIAlertView *alert = [[UIAlertView alloc]       initWithTitle:nil
>                                                                        message:NSLocalizedString(SMConstNoInternetConnectionAlertMessage,
> nil)
>                                                                        delegate:self
>                                                                        cancelButtonTitle:@"OK"
>                                                                        otherButtonTitles:nil];
>                [alert show];
>                [alert release];
>                }
>        }
> -=-=-=-=-
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: iPhone Testing Internet Connection?
      • From: Chunk 1978 <email@hidden>
References: 
 >iPhone Testing Internet Connection? (From: Chunk 1978 <email@hidden>)

  • Prev by Date: iPhone Testing Internet Connection?
  • Next by Date: Re: iPhone Testing Internet Connection?
  • Previous by thread: iPhone Testing Internet Connection?
  • Next by thread: Re: iPhone Testing Internet Connection?
  • Index(es):
    • Date
    • Thread