I'm creating a simple iphone application and there I need to check the internet availability. To check this most the forums recommended to use the reachability class. Based on that I have implemented the following code.
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) {
isInternetConnectionAvailable = NO;
}
BOOL isReachable = flags & kSCNetworkFlagsReachable;
BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
NSURL *testURL = [NSURL URLWithString:serviceEndPoint];
NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5.0];
[[[NSURLConnection alloc] initWithRequest:testRequest delegate:self] autorelease];
However, I wish to have a simple alternative method to get the network status. In iphone it displays the network status itself,if i can reuse it then the overhead of checking the availability through my application can be eliminated. I found some new way of getting it through notifications, but still I couldn't get more details about it.
If anyone come across with a simple method to get it done this please share with me.