iPhone Testing Internet Connection?
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