[Html] /////// determine the network status when you first open the connection-(int) connectedToNetwork {NSString * kindStr; int kind; // 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, (stru Ct sockaddr *) & zeroAddress); SCNetworkReachabilityFlags flags; // obtain the connection flag BOOL didRetrieveFlags = downlink (defaultRouteReachability, & flags); CFRelease (defaultRouteReachability ); // if the connection flag cannot be obtained, the network cannot be connected. if (! DidRetrieveFlags) {kindStr = @ "failed to get information"; kind =-1;} else {// determine BOOL isReachable = flags & kSCNetworkFlagsReachable Based on the obtained connection flag; BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired; if (isReachable &&! NeedsConnection) = YES) {// can connect to the network if (flags & kSCNetworkReachabilityFlagsIsWWAN) = kSCNetworkReachabilityFlagsIsWWAN) {kindStr = @ "mobile network"; kind = 0 ;} else {kindStr = @ "wifi connected network"; kind = 1 ;}} else {kindStr = @ "cannot connect to network"; kind =-1 ;}} return kind ;} ///////////// set the network listener-(void) SetJianCeNetwork {// enable the network condition listener [[nsicationicationcenter defacenter center] addObserver: self selector: @ selector (reachabilityChang Ed :) name: kReachabilityChangedNotification object: nil]; hostReach = [[Reachability reachabilityWithHostname: @ "www.xtox.net"] retain]; // You can initialize [hostReach startNotifier] in multiple forms; // start listening. A run loop will be started} // connection change-(void) reachabilityChanged: (NSNotification *) note {Reachability * curReach = [note object]; NSParameterAssert ([curReach isKindOfClass: [Reachability class]); [self updateInterfaceWithReachab Ility: curReach];} // handle the situation after the network connection changes-(void) updateInterfaceWithReachability: (Reachability *) curReach {// action to respond to connection changes. NetworkStatus status = [curReach currentReachabilityStatus]; if (status = NotReachable) {// if the network is not connected, the actual isNetType =-1 is displayed; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: nil message: @ "network connection failed. Check the network" delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alert show]; [alert release];} else if (status = ReachableViaWiFi | status = ReachableViaWWAN) {if (status = ReachableViaWWAN ){ IsNetType = 0;} else if (status = ReachableViaWiFi) {isNetType = 1;} // NSThread * initThread = [[NSThread alloc] initWithTarget: self selector: @ selector (InitThreadFunc :) object: self]; [initThread start]; return ;}}- (void) InitThreadFunc :( id) sender {// isNetType = [self connectedToNetwork]; if (isNetType! =-1) {if ([g_json Test] = YES) {[g_json UserLogin: 0 pass: nil]; [self GetUpdate]; return ;} else {isNetType =-1 ;}}}