Is it wise to use Reachability to check for a remote host's availability?

前端 未结 6 1012
不知归路
不知归路 2021-01-01 05:59

Is it wise to use Reachability Class(from Apple) to check for a remote host\'s availability ? say for example, www.google.com

or should I use

NSStri         


        
6条回答
  •  隐瞒了意图╮
    2021-01-01 06:41

    The following code from developer.apple.com might help you..

    // Create the request.
    
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]
    
                            cachePolicy:NSURLRequestUseProtocolCachePolicy
    
                        timeoutInterval:60.0];
    
    // create the connection with the request
    
    // and start loading the data
    
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    
    if (theConnection) {
    
        // Create the NSMutableData to hold the received data.
    
        // receivedData is an instance variable declared elsewhere.
    
        receivedData = [[NSMutableData data] retain];
    
    } else {
    
        // Inform the user that the connection failed.
    
    }
    

提交回复
热议问题