2013-01-18 73 views

回答

8

使用可達性類。

if([self checkInternetConnected]) 
    { 
    NSLog(@"Internet connected\n"); 
    } 


- (BOOL)checkInternetConnected 
{ 
    Reachability *reachability = [Reachability reachabilityForInternetConnection]; 
    NetworkStatus networkStatus = [reachability currentReachabilityStatus]; 
    return !(networkStatus == NotReachable); 
} 

你可以得到rechability類here : Download sample並添加Reachability.h和Reachability.m到您的項目。

+0

然後你必須添加:SystemConfiguration.framework如果你還沒有添加它!祝你好運 –