• 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
iPhone Testing Internet Connection?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

iPhone Testing Internet Connection?


  • Subject: iPhone Testing Internet Connection?
  • From: Chunk 1978 <email@hidden>
  • Date: Tue, 15 Dec 2009 07:25:03 -0500

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

  • Follow-Ups:
    • Re: iPhone Testing Internet Connection?
      • From: David Duncan <email@hidden>
    • Re: iPhone Testing Internet Connection?
      • From: Jonathan del Strother <email@hidden>
  • Prev by Date: Re: pls explain rotated iPhone coordinates to me
  • Next by Date: Re: iPhone Testing Internet Connection?
  • Previous by thread: Re: NSPredicate like NSLiteralSearch
  • Next by thread: Re: iPhone Testing Internet Connection?
  • Index(es):
    • Date
    • Thread