1. Confirm the network environment 3g/WiFi 1. Confirm the network environment, connection conditions, and other information when you add source files and framework to develop Web applications. If they are not processed, they will not be reviewed by Apple. Apple's routine reachability describes how to obtain/detect the network status. To use Reachability in an application, complete the following two steps: 1.1. add source file: to use Reachability in your program, you only need to Reachability in this routine. H and reachability. copy m to your project. Example: 1. 2. Add framework: Add systemconfiguration. Framework to the project. Example: 2. network Status reachability. h defines three network statuses: C code collection code typedef Enum {notreachable = 0, // reachableviawifi is not connected, // use 3g/GPRS network reachableviawwan // use WiFi network} networkstatus; therefore, you can check the network status as follows: C code favorites code reachability * r = [reachability reachabilitywithhostname: @ "www.apple.com"]; Switch ([R currentreachabilitystatus]) {Case notreachable: // No network connection break; Case reachableviawwan: // use 3G network break; Case reachableviawifi :// Use WiFi break;} 3. when the current network Environment Program is started, if you want to check the available network environment, you can add code + (bool) to the wific code favorites like this) isenablewifi {return ([[reachability reachabilityforlocalwifi] currentreachabilitystatus]! = Notreachable);} // whether it is 3G + (bool) isenable3g {return ([reachability reachabilityforinternetconnection] currentreachabilitystatus]! = Notreachable);} example:-(void) viewwillappear :( bool) animated {If ([reachability reachabilityforinternetconnection]. currentreachabilitystatus = notreachable) & ([reachability reachabilityforlocalwifi]. currentreachabilitystatus = notreachable) {self. navigationitem. hidesbackbutton = yes; [self. navigationitem setleftbarbuttonitem: Nil animated: No] ;}} 4. real-time notification of the network connection status is checked in real time, and notification is also necessary in network applications. When the connection status changes, you must promptly notify the user: C code reachability 1.5 version/My. appdelegate. h # import "reachability. H "@ interface myappdelegate: nsobject <uiapplicationdelegate> {networkstatus remotehoststatus;} @ property networkstatus remotehoststatus; @ end // my. appdelegate. M # import "myappdelegate. H "@ implementation myappdelegate @ synthesize remotehoststatus; // update the network status-(void) updatestatus {self. remotehoststatus = [[reachability sharedreachability] remotehoststatus];} // notification network status-(void) reachabilitychanged :( nsnotification *) Note {[self updatestatus]; If (self. remotehoststatus = notreachable) {alert * Alert = [[delealloc] initwithtitle: nslocalizedstring (@ "appname", nil) message: nslocalizedstring (@ "notreachable", nil) delegate: nil cancelbuttontitle: @ "OK" otherbuttontitles: Nil]; [alert show]; [alert release] ;}// program initiator, starts the network monitoring C code to add code to favorites-(void) applicationdidfinishlaunching :( uiapplication *) Application {// sets the network detection site [[reachability sharedreachability] sethostname: @ "www.apple.com"]; [[reachability sharedreachability] setnetworkstatusnotificationsenabled: Yes]; // set the notification function when the network status changes [[nsicationicationcenter defaultcenter] addobserver: Self selector: @ selector (reachabilitychanged :) name: @ "knetworkreachabilitychangednotification" Object: Nil]; [self updatestatus];}-(void) dealloc {// Delete the notification object [[nsicationicationcenter defacenter center] removeobserver: Self]; [Window release]; [Super dealloc];} reachability 2.0 // myappdelegate. h @ Class reachability; @ interface myappdelegate: nsobject <uiapplicationdelegate> {reachability * hostreach;} @ end // myappdelegate. m-(void) reachabilitychanged :( nsnotification *) Note {reachability * curreach = [Note object]; nsparameterassert ([curreach iskindofclass: [reachability class]); networkstatus status = [curreach failed]; If (status = notreachable) {uialertview * Alert = [[uialertview alloc] initwithtitle: @ "appname" "message: @" notreachable "delegate: nil cancelbuttontitle: @ "yes" otherbuttontitles: Nil]; [alert show]; [alert release] ;}}-(void) applicationdidfinishlaunching :( uiapplication *) Application {//... // monitor network conditions [[nsicationicationcenter defacenter center] addobserver: Self selector: @ selector (reachabilitychanged :) name: kreachabilitychangednotification object: Nil]; hostreach = [[reachability reachabilitywithhostname: @ "www.google.com"] retain]; hostreach startcycler]; //...}