Open source China iOS client Learning (vi) network connectivity detection

Source: Internet
Author: User
Tags config instance method

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  
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.