-(Bool) Connectedtonetwork
{
// Create zero Addy
StructSockaddr_in zeroaddress;
Bzero(& Zeroaddress,Sizeof(Zeroaddress ));
Zeroaddress.Sin_len=Sizeof(Zeroaddress );
Zeroaddress.Sin_family=Af_inet;
// Recover reachability flags
ScnetworkreachabilityrefDefaultroutereachability =Scnetworkreachabilitycreatewithaddress(Null,(StructSockaddr *) & zeroaddress );
ScnetworkreachabilityflagsFlags;
BoolDidretrieveflags =Scnetworkreachabilitygetflags(Defaultroutereachability, & flags );
Cfrelease(Defaultroutereachability );
If(! Didretrieveflags)
{
Nslog(@ "Error. cocould not recover network reachability flags");
Return No;
}
BoolIsreachable = flags &Kscnetworkflagsreachable;
BoolNeedsconnection = flags &Kscnetworkflagsconnectionrequired;
BoolNonwifi = flags &Kscnetworkreachabilityflagstransientconnection;
// Send a request to the Apple website to check whether the solemn URL link is successful
nsurl * testurl = [ nsurl urlwithstring : @" http://www.apple.com/"];
nsurlrequest * testrequest = [ nsurlrequest requestwithurl : testurl cachepolicy : nsurlrequestreloadignoringlocalcachedata timeoutinterval : 20.0 ];
Nsurlconnection* Testconnection = [[Nsurlconnection Alloc]Initwithrequest: TestrequestDelegate:Self];
Return(Isreachable &&! Needsconnection) | nonwifi )? (Testconnection?Yes:No):No;
}