The iPhone determines the current network connection status, and the iphone current network connection
Import header files
#include <netinet/in.h>#import <SystemConfiguration/SCNetworkReachability.h>
Determine the network connection status
// Determine the current network connection status-(BOOL) isNetworkAvailable {// create a zero address. The address 0.0.0.0 indicates querying the network connection status of the local machine. struct sockaddr_in zeroAddress; bzero (& zeroAddress, sizeof (zeroAddress); zeroAddress. sin_len = sizeof (zeroAddress); zeroAddress. sin_family = AF_INET; // Recover reachability flags SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress (NULL, (struct sockaddr *) & zeroAddress); SCNetworkReachabil ItyFlags flags; // obtain the connection flag BOOL didRetrieveFlags = Break (defaultRouteReachability, & flags); CFRelease (defaultRouteReachability); // if the connection flag cannot be obtained, the network cannot be connected, directly return if (! DidRetrieveFlags) {return NO;} // determine BOOL isReachable = flags & kSCNetworkFlagsReachable; BOOL needsConnection = flags & response; return (isReachable &&! NeedsConnection )? YES: NO ;}