i don't have access to an iPhone for testing (only an iPod touch). i've read some forum posts claiming that the code listed below will only work with wifi, and not a cellular connection. is this true?
Code:
- (BOOL)internetConnection
{
//INTERNET CONNECTION TESTING
//Add the SystemConfiguration framework
//#import <SystemConfiguration/SCNetworkReachability.h>
//#import <netinet/in.h>
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 didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
CFRelease(defaultRouteReachability);
if (!didRetrieveFlags)
return 0;
BOOL isReachable = flags & kSCNetworkFlagsReachable;
BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
return (isReachable && !needsConnection) ? YES : NO;
}
- (IBAction)gotoAppStore
{
if ([self internetConnection] == YES)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=kAppId"]];
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:NSLocalizedString(SMConstNoInternetConnectionAlertMessage, nil)
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}