Open source China iOS client based on the network synchronization of data, so as to see the same data as the Web page, so the start of the program needs to check the network; This is also the first step in each networking application, if the network application does not check the Internet, Apple will not be audited;
Open source China iOS client Daniel is very confusing when writing network detection, began to think they use ASI class library do network detection, today just see understand, they are not used ASI class library detection, but use to afnetworking this class library an instance method to do network connection detection;
First look at the Appdelegate file:
In the Application:didfinishlaunchingwithoptions: method
Check if the network exists if it does not exist pop-up prompts
[Config instance].isnetworkrunning = [Checknetwork isexistencenetwork];
In the Applicationdidbecomeactive: method
-(void) Applicationdidbecomeactive: (uiapplication *) application
{
[Config instance].isnetworkrunning = [ Checknetwork Isexistencenetwork];
if ([Config instance].isnetworkrunning = = NO) {
Uialertview *myalert = [[Uialertview alloc] initwithtitle:@ ' warning ' Messa ge:@ "Disconnected network, will use off-line mode" delegate:self cancelbuttontitle:@ "confirm" otherbuttontitles:nil,nil];
[Myalert show];
}
have been used [config instance].isnetworkrunning = [checknetwork isexistencenetwork]; and then look at config and checknetwork. Two class definitions
The instance method of the Config class,
Static Config * instance = nil;
+ (Config *) Instance
{
@synchronized (self)
{
if (nil = = Instance)
{
[self new]
}
}
return instance;
}
The literal meaning can also be measured is to cinfig class instantiation, isnetworkrunning is the BOOL type variable
Checknetwork in Asihttp file, and ASI class Library put a piece of, (inside Chinese characters appear garbled)
+ (BOOL) isexistencenetwork
{
// bool isexistencenetwork; reachability *r = [reachability reachabilitywithhostname:@ "www.oschina.net"]; switch ([R Currentreachabilitystatus]) {
//Case notreachable:
// isexistencenetwork= FALSE; // NSLog (@ "Ideal ℃ 湁 network 戠 粶");
Break ;
Case Reachableviawwan:
// isexistencenetwork=true; // NSLog (@ "Girls e 湪 raccoon 敤 3G network 戠 粶");
Break ;
Case Reachableviawifi:
// isexistencenetwork=true; // NSLog (@ "Girls e 湪 raccoon 敤 wifi network 戠 粶");
Break ; }
//return isexistencenetwork;
Return YES
}