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

前端 未结 6 1048
不知归路
不知归路 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:30

    Here is a tutorial on how to use Reachability. http://www.raddonline.com/blogs/geek-journal/iphone-sdk-testing-network-reachability/

    NSString *connectedString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com/"]]; 
    
    if ([connectedString length] != 0) // Host Available
    

    The code you provided should also work but might not give the desired result.. Reachability is more reliable..

提交回复
热议问题