+(
BOOL
)connectedToNetwork{
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)
{
NSLog(
@"Error. Could not recover network reachability flags"
);
return
NO
;
}
BOOL
isReachable = flags & kSCNetworkFlagsReachable;
BOOL
needsConnection = flags & kSCNetworkFlagsConnectionRequired;
return
(isReachable && !needsConnection) ?
YES
:
NO
;
}