iPhone - check if internet connectivity is available or not
<p>I am using the following code to find out whether internet connectivity is present or not.</p>

<pre><code>struct sockaddr_in zeroAddress; 
bzero(&amp;zeroAddress, sizeof(zeroAddress)); 
zeroAddress.sin_len = sizeof(zeroAddress); 
zeroAddress.sin_family = AF_INET;

// Recover reachability flags
SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr*)&amp;zeroAddress); 
SCNetworkReachabilityFlags flags; 
BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &amp;flags); 
CFRelease(defaultRouteReachability); 
if (!didRetrieveFlags) { 
    NSLog(@"Error. Could not recover network reachability flags"); 
    return 0; 
} 
BOOL isReachable = flags &amp; kSCNetworkFlagsReachable; 
BOOL needsConnection = flags &amp; kSCNetworkFlagsConnectionRequired; 
return (isReachable &amp;&amp; !needsConnection) ? YES : NO;
</code></pre>

<p>This method returns the expected result when my device is connected to a wifi network. But if I test the same method on a 3G or an Edge network, it returns a NO (i.e. not connected to the internet)</p>

<p>Any ideas why?</p>

<p>Thanks.</p>
