2009-11-26 144 views
0

如何通过iphone或objective-c检查互联网连接?互联网问题

+0

类似:http://stackoverflow.com/questions/1083701/how-to-check-for-an-active-internet-connection-on -iphone-sdk – miku 2009-11-26 10:52:59

+0

重复http://stackoverflow.com/questions/1802592/internet-problem/1802657 – Lee 2009-11-26 11:02:27

回答

0

Quick and Drity:Ping Google?

0

看一看苹果的示例代码可达性。它应该为你提供你需要的一切。

2

下面的代码片段,您可以使用:

[[Reachability sharedReachability] setHostName:@"example.com"]; 
if ([[Reachability sharedReachability] remoteHostStatus] == NotReachable) { 
    UIAlertView *dialog = [[[UIAlertView alloc] init] retain]; 
    [dialog setTitle:@"Server unreachable"]; 
    [dialog setMessage:@"The server is temporarily unavailable."]; 
    [dialog addButtonWithTitle:@"OK"]; 
    [dialog show]; 
    [dialog release]; 
}